I want member routes generating by resources
to contain additional parameter.
Something like:
resources :users
with folowing routes:
users/:id/:another_param
users/:id/:another_param/edit
Any ideas ?
resources
method doesn't allow to do that. But we can do something similar using the path
option including extra parameters:
resources :users, path: "users/:another_param"
This will generate urls like this:
users/:another_param/:id
users/:another_param/:id/edit
In this case we will need to send :another_param
value to routing helpers manually:
edit_user_path(@user, another_param: "another_value")
# => "/users/another_value/#{@user.id}/edit"
Passing :another_param
value is not required if a default value has been set:
resources :users, path: "users/:another_param", defaults: {another_param: "default_value"}
edit_user_path(@user) # => "/users/default_value/#{@user.id}/edit"
Or we can even make the extra parameter not necessary in the path:
resources :users, path: "users/(:another_param)"
edit_user_path(@user) # => "/users/#{@user.id}/edit"
edit_user_path(@user, another_param: "another_value")
# => "/users/another_value/#{@user.id}/edit"
# The same can be achieved by setting default value as empty string:
resources :users, path: "users/:another_param", defaults: {another_param: ""}
If we need extra parameters for only certain actions, it can be done like this:
resources :users, only: [:index, :new, :create]
# adding extra parameter for member actions only
resources :users, path: "users/:another_param/", only: [:show, :edit, :update, :destroy]
you could do something more explicit like
get 'my_controller/my_action/:params_01/:params_02', :controller => 'my_controller', :action => 'my_action'
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