How do I resolve Rails 5.2.4.2 routing error: No route matches [GET] "/pages_about_path"?
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
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.