will_paginate 将 url 与设计经过身份验证的根路由混淆
will_paginate confusing urls with devise authenticated root routes
我的 routes.rb 中有以下内容:
...
authenticated :user do
root to: 'game_shelves#index', as: :authenticated_root
end
unauthenticated do
root to: 'editions#index'
end
...
resources :editions, :path => "games" do
collection do
get 'to_review'
post 'review'
get 'existing_work'
end
member do
put 'split'
end
resources :expansions do
end
end
...
will_paginate是这样的:
<%= will_paginate @collection, renderer: BootstrapPagination::Rails %>
结果链接是这样的:
如果我将 unauthenticated root 设置为除 editions#index 之外的其他内容,则链接是正确的,如下所示:
我试过使用这个:
<%= will_paginate @collection, :params => {:controller => '/editions', :action => 'index'}, renderer: BootstrapPagination::Rails %>
但它并不强制will_paginate使用正确的路线。如果我试试这个:
<%= will_paginate @collection, :params => {:controller => editions_path }, renderer: BootstrapPagination::Rails %>
Rails 给我路线错误:
No route matches {:action=>"index", :controller=>"games", :page=>2}
我已经反转了我的 routes.rb,它现在可以工作了。看来顺序很重要,我没意识到。
...
resources :editions, :path => "games" do
collection do
get 'to_review'
post 'review'
get 'existing_work'
end
member do
put 'split'
end
resources :expansions do
end
end
authenticated :user do
root to: 'game_shelves#index', as: :authenticated_root
end
unauthenticated do
root to: 'editions#index'
end
我的 routes.rb 中有以下内容:
...
authenticated :user do
root to: 'game_shelves#index', as: :authenticated_root
end
unauthenticated do
root to: 'editions#index'
end
...
resources :editions, :path => "games" do
collection do
get 'to_review'
post 'review'
get 'existing_work'
end
member do
put 'split'
end
resources :expansions do
end
end
...
will_paginate是这样的:
<%= will_paginate @collection, renderer: BootstrapPagination::Rails %>
结果链接是这样的:
如果我将 unauthenticated root 设置为除 editions#index 之外的其他内容,则链接是正确的,如下所示:
我试过使用这个:
<%= will_paginate @collection, :params => {:controller => '/editions', :action => 'index'}, renderer: BootstrapPagination::Rails %>
但它并不强制will_paginate使用正确的路线。如果我试试这个:
<%= will_paginate @collection, :params => {:controller => editions_path }, renderer: BootstrapPagination::Rails %>
Rails 给我路线错误:
No route matches {:action=>"index", :controller=>"games", :page=>2}
我已经反转了我的 routes.rb,它现在可以工作了。看来顺序很重要,我没意识到。
...
resources :editions, :path => "games" do
collection do
get 'to_review'
post 'review'
get 'existing_work'
end
member do
put 'split'
end
resources :expansions do
end
end
authenticated :user do
root to: 'game_shelves#index', as: :authenticated_root
end
unauthenticated do
root to: 'editions#index'
end