I''ve written a Image Gallery app in rails. It contains photo albums, in
which you can upload photos, then click on an individual photo to view
it''s larger size. When you bring up the larger size, I have previous
and
next buttons to go through the photos in the album. My problem is when
navigating through photos via the next and previous buttons, it scrolls
through ALL photos instead of photos only in that album.
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/.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.