Previous and Next buttons in picture.html.erb
<section id="prev">
<%= link_to("Previous", @photo.previous_photo) if
@photo.previous_photo %>
</section>
<section id="next">
<%= link_to("Next", @photo.next_photo) if @photo.next_photo %>
</section>
Methods in model
def previous_photo
self.class.first(:conditions => ["id < ?", id], :order => "id desc")
end
def next_photo
self.class.first(:conditions => ["id > ?", id], :order => "id asc")
end
Method in Albums Controller
def picture
@photo = Photo.find(params[:id])
end
I tried doing it like this:
<%= link_to("Previous", @album.photo.previous_photo) if
@album.photo.previous_photo %>
def picture
@album = Album.find(params[:id])
@photo = Photo.find(params[:id])
end
With this result:
Couldn't find Album with ID=25
--
Posted via http://www.ruby-forum.com/.