Reputation: 2953
I have a static_controller
with index
action where an id is needed
My routes
get 'faqs' => 'static#main'
get 'faqs/:id' => 'static#index'
but if I use this path faqs_path(faq_id)
I get
http://localhost:5000/faq.1
instead of http://localhost:5000/faq/1
Could someone tell me how to fix this. Thank you..
Upvotes: 0
Views: 235
Reputation: 211560
You may need to name them properly:
get 'faqs' => 'static#main', as: 'faqs'
get 'faqs/:id' => 'static#index', as: 'faq'
Normally you do this with resources
where you try to adhere to REST conventions, but in your case if you really need them this way you'll have to coach the router.
Check with rake routes
that the names are correct. You may have been calling faqs_path
with the id
going in as the optional :format
specifier.
Upvotes: 2
Reputation: 2973
I think your problem here is same routes name, you can change your name as:
get 'faqs/:id' => 'static#index'
get 'faqs' => 'static#main'
to
get 'faq/:id' => 'static#index'
get 'faqs' => 'static#main'
And your path
is: faq_path(faq_id)
Tell me if it didn't work.
Upvotes: 0