Using will_paginate with multiple models (Rails)

前端 未结 4 475
生来不讨喜
生来不讨喜 2020-12-28 11:34

Pretty sure that I\'m missing something really simple here:

I\'m trying to display a series of pages that contain instances of two different models - Profiles and Gr

4条回答
  •  孤独总比滥情好
    2020-12-28 12:05

    You can get close doing something like:

    @profiles, @groups = [Profile, Group].map do |clazz|
      clazz.paginate(:page => params[clazz.to_s.downcase + "_page"], :order => 'name')
    end
    

    That will then paginate using page parameters profile_page and group_page. You can get the will_paginate call in the view to use the correct page using:

    <%= will_paginate @profiles, :page_param => 'profile_page' %>
    ....
    <%= will_paginate @groups, :page_param => 'group_page' %>
    

    Still, I'm not sure there's a huge benefit over setting up @groups and @profiles individually.

提交回复
热议问题