using params in a comparison

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.

Obviously photo.other does not equal params[:id]

What is .other?

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.

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...@gmail.com>

  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]

exactly what i was looking for. thanks.

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.

Wow, thanks a ton for that concise description ... that just saved me probably an hour of digging in one of my books.