Naming params of nested routes

后端 未结 3 726
深忆病人
深忆病人 2021-01-14 06:54
resources :leagues do
  resources :schedule
end

This generates:

leagues/:id
leagues/:league_id/schedule/:id

How c

3条回答
  •  [愿得一人]
    2021-01-14 07:09

    It appends the ID to the nested_param which is a bummer because I would like mine to be without the singular name. It looks like they really don't want you to make it only like :id as it could have conflicts. Plus it would be a bit of a diff from the normal restful routing that rails likes to use.

    https://github.com/rails/rails/blob/5368f2508651c92fbae40cd679afbafdd7e98e77/actionpack/lib/action_dispatch/routing/mapper.rb#L1207

    namespace :account, defaults: { type: 'account' }do
      resources :auth, param: :lies_id, only: [] do
        get :google
      end
    end
    

    Rake routes returns the following

    $ rake routes | grep /account/auth
    account_auth_google GET  /account/auth/:auth_lies_id/google(.:format)
    

    So the solution which seams simpler is to just change the controller to use the nested param name it creates.

提交回复
热议问题