The tutorials are then displayed in order of there id (auto-
incrementing) in their categories show method.
The thing is, I want to create a link that goes from one tutorial
(with an id of 10 for example) to the next tutorial in that category
(which might not have an id of 11, as I create different tutorials at
different times, therefore creating different ids for two tutorials
seemingly next to eachother in order).

Obviously I know I will need something like this:
<%= link_to 'Next lesson....',   %>

but I just don't know how I can manage it..

By the way, every tutorial has a: category_id  to determain which
category they are in (this is an integer).


If I were you, i'd create a position column on tutorials, which
determines the ordering of tutorials for a category (ordering by id
might seem the simplest but stops you from ever reordering tutorials.
Given a tutorial, the next one is the first one in the same category
whose position is greater than the current ones (you could write a
next_tutorial method on tutorial). There's a plugin called
acts_as_list that you might find helpful maintaining the position
column. If you're hell bent on ordering by id then it's as if id is
your position column

Fred

I agree with Fred as it allows you to easily re-order the tutorials if you want to, but if you don't... then...

next_tutorial = Tutorial.find(:conditions => ["id > ? AND category_id = ?", current_tutorial_id, current_category_id], :order => 'id', :limit => 1)

prev_tutorial = Tutorial.find(:conditions => ["id < ? AND category_id = ?", current_tutorial_id, current_category_id], :order => 'id DESC', :limit => 1)

--
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-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to