Reputation: 6451
I have a resources :posts
. How can I customize it's paths to the following and also ability to call it with the normal resource path names:
URL Controller action Helper function
'q' 'posts#index' posts_path
'q/(:id)' 'posts#show' post_path(:id)
'ask' 'posts#new' new_post_path
'q' 'posts#create' posts_path
Here is what I've tried and doesn't work as the expected result above...
get 'q' => 'posts#index', as: :posts
get 'q/(:id)' => "posts#show", as: :post
get 'ask' => 'posts#new'
Upvotes: 0
Views: 38
Reputation: 29379
You're presumably getting an error because you're trying to assign a route name that is already in use.
The resources posts
call results in a definition for the posts
and post
routes. If you change your as: ..
clause to reference different (unused) names, you will no longer get that error.
Upvotes: 1