Ask A Question

Notifications

You’re not receiving notifications from this thread.

How do I resolve Rails 5.2.4.2 routing error: No route matches [GET] "/pages_about_path"?

Alfred Montalvo Jr asked in Rails

I am running into a routing error for a get action when I try to render an html erb view from the '../views/pages' folder via a navbar link.

I have reviewed the routes.rb file and the output from "rake routes" to verify that route for the 'about' view has been defined in the routes file.

So I do not understand why the routing error is happening when the path is defined in the route file correctly.

I have listed below the url helper that I am using in the navbar, my routes.rb file and the output from rake routes.

Does anyone have any suggestions to resolve the routing error that I am encountering?

url helper defined in _nav.html.erb:

<li class="nav-item">
  <a class="nav-link" href="pages_about_path">About</a>
</li>

routes.rb:

Rails.application.routes.draw do
  root to: 'pages#index'  
  get 'pages/about', to: 'pages#about'  
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
end

rake routes output:

Prefix Verb URI Pattern Controller#Action
root GET / pages#index

pages_about GET /pages/about(.:format) pages#about

Reply

Hey Alfred,

Can you post your actual error?

Reply

Actually, think I spotted your error. You're not using ERB for rendering the link.

<a class="nav-link" href="pages_about_path">About</a>

That should be:

<%= link_to "About", pages_about_path, class: "nav-link" %>

pages_about_path is a helper in Rails to generate the string /pages/about for your route. You need to use ERB to make sure it runs that code and outputs href="/pages/about" instead of outputting the raw string of href="pages_about_path".

Reply

Hi Chris,
thank you very much for providing the solution to the routing error I was running into.

Reply

Thank you for the information

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,796+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.