Hi, i will keep this short: <% for photo in @photos -%> <% if photo.other == params[:id] %> <%= link_to image_tag(photo.public_filename(:thumb)) %> <% end %> <% end %> This is the code Im using and it is not displaying anything. All the values are stored correctly and params[:id] has the correct value. I think there is something wrong in the comparison: if photo.other =params[:id]. Can you use the params hash to make comparisons like this? thanks. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Obviously photo.other does not equal params[:id] What is .other? On Wed, May 28, 2008 at 10:34 AM, Dave Lynam <dlynam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, i will keep this short: > > <% for photo in @photos -%> > <% if photo.other == params[:id] %> > <%= link_to image_tag(photo.public_filename(:thumb)) %> > <% end %> > <% end %> > > This is the code Im using and it is not displaying anything. All the > values are stored correctly and params[:id] has the correct value. I > think there is something wrong in the comparison: if photo.other => params[:id]. Can you use the params hash to make comparisons like > this? > > thanks. > > >-- Appreciated my help? Recommend me on Working With Rails http://workingwithrails.com/person/11030-ryan-bigg --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Other is a column in the database. So photo.other is the value in this column and I only want to display the photos where the params[:id] matches this photo.other value. On May 27, 6:29 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Obviously photo.other does not equal params[:id] > > What is .other? > > > > On Wed, May 28, 2008 at 10:34 AM, Dave Lynam <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, i will keep this short: > > > <% for photo in @photos -%> > > <% if photo.other == params[:id] %> > > <%= link_to image_tag(photo.public_filename(:thumb)) %> > > <% end %> > > <% end %> > > > This is the code Im using and it is not displaying anything. All the > > values are stored correctly and params[:id] has the correct value. I > > think there is something wrong in the comparison: if photo.other => > params[:id]. Can you use the params hash to make comparisons like > > this? > > > thanks. > > -- > Appreciated my help? > Recommend me on Working With Railshttp://workingwithrails.com/person/11030-ryan-bigg--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dave Lynam wrote:> Other is a column in the database. So photo.other is the value in > this column and I only want to display the photos where the > params[:id] matches this photo.other value. > > On May 27, 6:29 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>123 == "123" #=> false The params hash contains strings. A database column stored as an integer, will return an integer. And an integer will not equate to a string. photo.other == params[:id].to_i or photo.other.to_s == params[:id] -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
exactly what i was looking for. thanks. On May 27, 6:56 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Dave Lynam wrote: > > Other is a column in the database. So photo.other is the value in > > this column and I only want to display the photos where the > > params[:id] matches this photo.other value. > > > On May 27, 6:29 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > 123 == "123" #=> false > > The params hash contains strings. A database column stored as an > integer, will return an integer. And an integer will not equate to a > string. > > photo.other == params[:id].to_i > > or > > photo.other.to_s == params[:id] > -- > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Just to add a bit of clarity: you should also keep in mind the Ruby idioms for object identity vs. object equality. This one still trips me up from time-to-time coming from Java to Ruby: The == and .eql? methods in Ruby compare object equality (typically) where as the == operator in Java compares object identity (do these variables reference the same object?). Typically .equal? is used to compare object identity in Ruby. ------------------------------------->> s1 = "Rubies are red" >> s2 = "Rubies are red" >> s1 == s2 => true >> s1.eql? s2 => true >> s1.equal? s2 => false------------------------------------->> s1 = "Rubies are red" >> s2 = s1 >> s1 == s2 => true >> s1.eql? s2 => true >> s1.equal? s2 => true------------------------------------- Notice in the first example the two string have the same value (the same sequence of characters), but do not have the same identity. In the second case both s1 and s2 refer to the same string and do have the same identity. On May 27, 10:04 pm, Dave Lynam <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> exactly what i was looking for. thanks. > > On May 27, 6:56 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Dave Lynam wrote: > > > Other is a column in the database. So photo.other is the value in > > > this column and I only want to display the photos where the > > > params[:id] matches this photo.other value. > > > > On May 27, 6:29 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > 123 == "123" #=> false > > > The params hash contains strings. A database column stored as an > > integer, will return an integer. And an integer will not equate to a > > string. > > > photo.other == params[:id].to_i > > > or > > > photo.other.to_s == params[:id] > > -- > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Wow, thanks a ton for that concise description ... that just saved me probably an hour of digging in one of my books. On May 27, 10:04 pm, Robert Walker <r0b3rt4...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Just to add a bit of clarity: you should also keep in mind the Ruby > idioms for object identity vs. object equality. This one still trips > me up from time-to-time coming from Java to Ruby: > > The == and .eql? methods in Ruby compare object equality (typically) > where as the == operator in Java compares object identity (do these > variables reference the same object?). Typically .equal? is used to > compare object identity in Ruby. > > ------------------------------------->> s1 = "Rubies are red" > >> s2 = "Rubies are red" > >> s1 == s2 => true > >> s1.eql? s2 => true > >> s1.equal? s2 => false > > ------------------------------------->> s1 = "Rubies are red" > >> s2 = s1 > >> s1 == s2 => true > >> s1.eql? s2 => true > >> s1.equal? s2 => true > > ------------------------------------- > > Notice in the first example the two string have the same value (the > same sequence of characters), but do not have the same identity. In > the second case both s1 and s2 refer to the same string and do have > the same identity. > > On May 27, 10:04 pm, Dave Lynam <dly...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > exactly what i was looking for. thanks. > > > On May 27, 6:56 pm, Alex Wayne <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > > wrote: > > > > Dave Lynam wrote: > > > > Other is a column in the database. So photo.other is the value in > > > > this column and I only want to display the photos where the > > > > params[:id] matches this photo.other value. > > > > > On May 27, 6:29 pm, "Ryan Bigg (Radar)" <radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > > > 123 == "123" #=> false > > > > The params hash contains strings. A database column stored as an > > > integer, will return an integer. And an integer will not equate to a > > > string. > > > > photo.other == params[:id].to_i > > > > or > > > > photo.other.to_s == params[:id] > > > -- > > > Posted viahttp://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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---