I have a site with several pictures on it. I would like the users to be able to scroll to the next and previous pictures. Right now I''m using @params["id"].next to get to the next picture. But I can''t figure out how to go backwards. (Now you all think "total noob" and I totally agree.) I have tried to do things like: <%= link_to "Next post.", :action => "show", id => (@params["id"] + 1) %> <%= link_to "Previous post.", :action => "show", id => (@params["id"] - 1) %> and countless other things, but none of them work. The main error I seem to get is: cannot convert Fixnum into String from things like "<%= @params["id"] + 1 %>". This is obviously saying that I have two different types of variables, but I can''t figure out how to change @params.["id"] to an integer. Please help me! I''m sure everyone on this list could answer! All help SINCERELY appreciated! --- [This E-mail scanned for viruses by Declude Virus]
> cannot convert Fixnum into String from things like "<%= @params["id"] + > 1 %>". This is obviously saying that I have two different types of > variables, but I can''t figure out how to change @params.["id"] to an > integer. Please help me! I''m sure everyone on this list could answer!@params["id"].to_i :) -- Micah Alles micah-T1YOP9nF7vWQ0r5V5wSIsA@public.gmane.org 616-776-6020 Software Journeyman Atomic Object LLC _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On 4/23/05, Michael Klein <michaelklein-fliffHUUhfJg9hUCZPvPmw@public.gmane.org> wrote:> <%= link_to "Next post.", :action => "show", id => (@params["id"] + 1) %> > <%= link_to "Previous post.", :action => "show", id => (@params["id"] - > 1) %>Micah answered your question, but I''d like to point out that this will break if you ever delete any of your entries (if you delete an entry, then the ID number can''t be found). You''ll have to get a little more creative with this. I''d recommend using the pagination helper. -- Urban Artography http://artography.ath.cx
On Saturday, April 23, 2005, 8:50:54 PM, Michael wrote:> The main error I seem to get is: cannot convert Fixnum into String > from things like "<%= @params["id"] + 1 %>>". This is obviously > saying that I have two different types of variables, but I can''t > figure out how to change @params.["id"] to an integer. Please help > me! I''m sure everyone on this list could answer!http://www.ruby-doc.org/core/ (Hint: class String, method to_i :) Gavin