views:

37

answers:

1

I have a Gallery application that has Album and Photo models.

I have the user search in the Album's show view (search in the specific album) and I store the results in a variable named @search in the show action of the controller.

I want to pass this variable to the Photo model's show page so when a user clicked on a particular picture from the Album's show page, it goes to the Photo show page for the picture and allows me to put previous and next links at the top so that i can have prev and next only change photos that are within the search results.

I am wondering how to pass the variable search in this way to make previous and next links possible in the photo model's show controller action.

Thanks! I hope this was fairly clear.

+1  A: 

Just add a :search => @search to the link_to statements that you create for your prev and next links. They'll be added automatically as get style parameters to the URLs that you can pull out and pass on in your controllers.

Chris
hey chris, could you clarify what you mean? I'm still a bit confused. For example, how would I put that into the <%= link_to "prev", @photo.previous_photo %>
bob
Sorry, didn't see this response.
Chris
<%= link_to "prev", :search => @photo.previous_photo %> -- then look for params[:search] in your controller. That will be the previous photo you can show to the user.
Chris