overrides the default resource identifier :id

  • Problem: wanted to make the url like /resources/other_identifier rather than the default id identifier /resources/123
  • Solution: use param
    • param: overrides the default resource identifier
    • Using rake routes CONTROLLER=controller_name command to check the overridden identifier, Rails may add prefix automatically
# routes.rb 
  resources :restaurants , param: :code do
    resources :register, only: :create
  end
# generated route => /restaurants/:restaurant_code/register
# controller
params[:restaurant_code]
#=> retrieve the overrides identifier value

Reference

results matching ""

    No results matching ""