Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Tutorial - Named Routes

I am currently working through the Rails Tutorial by Michael Hartl and have run into an error I can't understand.

There is a section where the tutorial explains how to create custom URI's in the routes.rb file. The tutorial explains that by coding this:

match '/about', to: 'static_pages#about'

named routes should automatically be created that look like this:

about_path => '/about'
about_url  => 'http://localhost:3000/about'

The following section then helps you work through fixing up rspec tests by replacing certain bits of code with these variables. But when I do this, I end up failing every test because all the "automatically created variables" can't be found...

Can anyone explain to me why they aren't being found or where I can look to see if they were in fact created already.

like image 508
Shawn Taylor Avatar asked Jun 16 '26 08:06

Shawn Taylor


1 Answers

As far as I'm aware, if you do not use as:, you do not get a named route. See the guides for more info.

In your example, you could do the following:

get '/about', to: 'static_pages#about', as: 'about'
like image 129
theIV Avatar answered Jun 18 '26 00:06

theIV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!