will_paginate令人困惑的网址与设计认证的根路由

时间:2015-02-05 16:13:44

标签: ruby-on-rails ruby-on-rails-4 devise will-paginate

我的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 %>

结果链接是这样的:

  

http://localhost:3000/?page=2

如果我将未经身份验证的root作为版本#index的其他内容,则链接是正确的,如下所示:

  

http://localhost:3000/games?page=2

我尝试过使用它:

<%= will_paginate @collection, :params => {:controller => '/editions', :action => 'index'}, renderer: BootstrapPagination::Rails %>

但它并没有强迫will_paginate使用正确的路线。如果我试试这个:

<%= will_paginate @collection, :params => {:controller => editions_path }, renderer: BootstrapPagination::Rails %>

Rails给我路线错误:

  

没有路线匹配{:action =&gt;“index”,:controller =&gt;“games”,:page =&gt; 2}

1 个答案:

答案 0 :(得分:0)

我已经颠倒了我的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