Thursday, May 6, 2010

Re: [Rails] Re: Finding the next item, in a group of items.

On 6 May 2010 16:41, Joe <joe@dev-hq.co.uk> wrote:
>  def self.next_lesson
>        find :all, :conditions => ["position > ? AND category_id  = ?",
> @tutorial_id, @category_id], :order => 'position', :limit => 1
>        end
>
> and then this code in the link:
>
> <%= link_to 'Next lesson.', @tutorial.next_lesson  %>

using "self" in the method name makes it a class method; so accessible
with "Tutorial.next_lesson". But you'd have to pass in the tutorial_id
and category_id.

Seriously - someone much earlier suggested using acts_as_list. Do. It
deals with all of this for you...

--
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@googlegroups.com.
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.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate