It's true that will_paginate in datamapper will fire off the request
to the database as soon as you send it the paginate command. So it
doesn't play nice with datamapper's lazy loading techniques.

However, Datamapper is pretty flexible, so it's very easy to
workaround in your view. For example, instead of running the paginate
in your controller, you can just run the paginate command in the view
in place of your kicker (each). It may get a little messy, since you
need to assign the result to a variable, but with the right view
helper wrapper, it can get much cleaner.

# in controller (no queries will be run yet)
@posts = @category.posts.active.latest

# in view
- posts = @posts.paginate(:page => params[:page])
- for post in posts
  = render_post(post)
= will_paginate(posts)

# with helper: http://gist.github.com/64912
= paginate(@posts) do |post|
  = render_post(post)


On Feb 14, 9:55 am, Jon Hancock <[email protected]> wrote:
> I am still using paginator although I have heard several
> recommendations to go with the leading will_paginate agnostic.
> The reason I did not switch is all the examples I see indicate it does
> not work well with datamapper "style".  datamapper exposes a chained
> style of querying such as "this_user.posts.draft_status".  The usage
> patterns for will_paginate seem that I would need to have seperete
> queries just for pagination that breaks this encapsulation and causes
> me to repeat logic already embedded in my models.
>
> Am I making the wrong assuptions?  Does someone have in-depth examples
> of using will_paginate (merb_paginate) in a style that leverage the
> preferred style of using datamapper?
>
> thanks, Jon
>
> On Feb 13, 1:46 am, Jacques Crocker <[email protected]> wrote:
>
> > The latest agnostic will paginate has been forked and optimized for
> > Merb compatibility. Now uses Merb::Config for default settings, and
> > gets rid of the Rails view cruft. Currently using it on several
> > projects and it seems to work great.
>
> >http://github.com/merbjedi/merb_paginate
>
> > It's also packaged up on RubyForge as merb_paginate (0.9.0). The 1.0
> > release will correspond to will_paginate 3.0, whenever that finally
> > comes out.
>
> > On Feb 12, 4:20 am, cool <[email protected]> wrote:
>
> > > Guys,
>
> > >   How can we do pagination in Merb
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to