bpokosh-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Nov-20 23:50 UTC
next and previous methods for a model
Anyone know of a plugin or gem that would create methods such as next and previous on a model to traverse among siblings? For example, @post.next and @post.prev. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I don''t know of any, sorry. In the past I''ve written two simple instance methods and two named_scopes in my models. named_scope :next, lambda {|post, user| { :conditions => ["created_at > ? and user_id = ?", post.created_at, user.id], :order => "created_at ASC" } } named_scope :prev, lambda {|post, user| { :conditions => ["created_at < ? and user_id = ?", post.created_at, user.id], :order => "created_at DESC" } } def next(user) Post.next(self, user).first end def prev(user) Post.prev(self, user).first end On Nov 20, 6:50 pm, bpok...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Anyone know of a plugin or gem that would create methods such as next > and previous on a model to traverse among siblings? For example, > @post.next and @post.prev.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
you could try acts_as_list --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---