I'm still new to Rails, and so I have this issue.
I have a controller name Client. In the routing I have:
resources :clients do
get 'confirmation_import/:page', action: :confirmation_import, on: :collection, :defaults => {:page => 1}
collection do
get :autocomplete
post :confirmation_import
post :import
end
end
As you can see, I'm using pagination. When I go back to the first page though, the page param is not used, so the link becomes /clients/confirmation_import
. From there I'm getting an error because a before_action
for show
action is being used, and it says my id
param is confirmation_import
. How do I fix this?
答案 0 :(得分:1)
通常路由从上到下匹配,因为show
操作的路由在confirmation_report
操作的路由之前定义,它将show
操作路由到confirmation_report
为id
。
因此,请在confirmation_report
路线之前设置show
的路线,如下所示:
get 'clients/confirmation_import/:page' => 'clients#confirmation_import, :defaults => {:page => 1}
resources :clients do
collection do
get :autocomplete
post :confirmation_import
post :import
end
end