0

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'
Hopstream
  • 6,391
  • 11
  • 50
  • 81

2 Answers2

1

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.

Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106
0

try resources :posts path => 'q'

chaitanya90
  • 697
  • 2
  • 8
  • 24