Skip to main content
Ask A Question
Notifications
You’re not receiving notifications from this thread.
Subscribe

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

Rails • Asked by Alfred Montalvo Jr

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


Hey Alfred,

Can you post your actual error?


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".


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


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 31,152+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.