Forum: Ruby on Rails Paginate @member.items?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
81194a50c0f9bd95d7832a77fdf371bd?d=identicon&s=25 CSN (Guest)
on 2006-02-13 22:13
(Received via mailing list)
Is there a quick and easy way to paginate something
like @member.items (Member with has_many :items)?
Right now I do in the controller:

@item_pages, @member_items = paginate :item,
  :conditions=>["member_id=?", @member.id],
  :per_page=>25,
  :order=>'datetime desc'

It'd be more DRY if this was possible:

@item_pages, @member_items = paginate @member.items,
  :per_page=>25,
  :order=>'datetime desc'

And even more so if it could all be done in the
template:

<% for item in @member.items(:limit=>25,
:offset=>params[:page]*25) %>
...
<% end %>

<%= pagination_links @member.items, offset, limit, ...
%>


Any ideas?

Thanks,
csn


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
703682e5658453d83f692fddb5607096?d=identicon&s=25 Sandeep Gudibanda (sgudibanda)
on 2007-11-09 22:28
Hi CSN,

Any luck with a solution for this prob? I am facing the same problem
now?

Regards,
Sandeep G


CSN wrote:
> Is there a quick and easy way to paginate something
> like @member.items (Member with has_many :items)?
> Right now I do in the controller:
>
> @item_pages, @member_items = paginate :item,
>   :conditions=>["member_id=?", @member.id],
>   :per_page=>25,
>   :order=>'datetime desc'
>
> It'd be more DRY if this was possible:
>
> @item_pages, @member_items = paginate @member.items,
>   :per_page=>25,
>   :order=>'datetime desc'
>
> And even more so if it could all be done in the
> template:
>
> <% for item in @member.items(:limit=>25,
> :offset=>params[:page]*25) %>
> ...
> <% end %>
>
> <%= pagination_links @member.items, offset, limit, ...
> %>
>
>
> Any ideas?
>
> Thanks,
> csn
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
This topic is locked and can not be replied to.