I am quite new at Ruby and Rails and this is stumping me:
I have in my rhtml file:
<%= render(:partial => "owner", :collection =>
@business.owners, :locals => { :that_value=> @params[:that_value] } )
%>
then in my partial:
<% if owner.id == that_value %>
<%= owner.name %> <%= owner.id %> <%= that_value%>
<% else %>
<%= owner.name %> <%= owner.id %>
<% end %>
<%= owner.id == that_value%>
<%=owner.id%> <%=that_value%>
owner.id == that_value evaluates to false every time, even when they
are really the same.
Sample output:
Owner Number1 1
False
1 2
Owner Number2 2
False
2 2
Owner Number3 3
False
3 2
I am an old C guy and I keep thinking that there must be some typing
error, like one of the “2” is a string and the other is an int, but I
thought ruby has no types. I am pretty stumped, hopefully someone can
help.
And if I change <% if owner.id == that_value %> to <% if owner.id <>
that_value %> it fails.
On Feb 21, 11:57 pm, “[email protected]” [email protected]
It’s really confusing because they both print out as being the same
(in this case 2) but they don’t compare to be equal with each other…
On Feb 22, 8:34 am, “[email protected]” [email protected]
[email protected] wrote:
It’s really confusing because they both print out as being the same
(in this case 2) but they don’t compare to be equal with each other…
On Feb 22, 8:34 am, “[email protected]” [email protected]
Your most likely comparing a string to an integer
1 == “1” #=> false
All params come in as strings. If you want it to be treated as an
integer, you can convert it easily.
1 == “1”.to_i #=> true
So in your locals hash you can do:
:locals => {:that_value => params[:that_value].to_i}