Here's my routes file
Dumb::Application.routes.draw do
# an auto-named route
get '/a/b', to: 'a#b'
# apparently not auto-named???
get '/a/z/:something', to: 'a#z'
end
Here's output of rake routes
a_b GET /a/b(.:format) a#b
GET /a/z/:something(.:format) a#z
Wow that sucks! At least for consistency's sake. If I change the a#z route to
get '/a/z/:something', to: 'a#z', as: "a_z"
rake routes will display
a_b GET /a/b(.:format) a#b
a_z GET /a/z/:something(.:format) a#z
Ok that's good, but having to name the route like that is annoying.
Is this the only solution?
My guess is that Rails can't assign a name to your route because it does not understand it. Usually, you will want to write your route as such :
/a/:id/b/:id # instead of /a/b/:id which Rails does not understand.
Rails maps a to a controller with a model instance with id :id and b to another controller with another model instance with id :id.
/a/b/:id does not refer to anything in terms of Rails convention.
Getting GET /a/b named to a_b was just a guess Rails made, but it can't work out GET /a/z/:something. What would it be? a_z_something?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With