Send(column.name) comparison problems

I am having trouble with what I thought would be a simple equality
comparison.

Here is the relevant code:

<% for ticket in @tickets %>

<% for column in Ticket.content_columns %> <% if column.human_name == "Status" %> <% if ticket.send(column.name).eql?("true") %> Open <% else %> Closed <% end %> <% else %> <%=h ticket.send(column.name) %> <% end %> <% end %>

My problem is as follows:

if ticket.send(column.name).eql?(“true”) always evaluates to false and
prints Closed.

I’ve also tried:
if ticket.send(column.name) == “true” but I get the same behavior.

When I try <%=h ticket.send(column.name) %> it get true

Any help would be most appreciated.

Try this

  <% if column.human_name == "Status" %>
   <% if ticket.Status == "true"  %>
    <td>Open</td>

[email protected] wrote:

I am having trouble with what I thought would be a simple equality
comparison.

Here is the relevant code:

<% for ticket in @tickets %>

<% for column in Ticket.content_columns %> <% if column.human_name == "Status" %> <% if ticket.send(column.name).eql?("true") %> Open <% else %> Closed <% end %> <% else %> <%=h ticket.send(column.name) %> <% end %> <% end %>

My problem is as follows:

if ticket.send(column.name).eql?(“true”) always evaluates to false and
prints Closed.

I’ve also tried:
if ticket.send(column.name) == “true” but I get the same behavior.

When I try <%=h ticket.send(column.name) %> it get true

Any help would be most appreciated.

That would work too, and be a lot cleaner.

Thanks!

Thanks!

Nevermind my bad. Passing true to eql? in the proper way fixed my
problem.

However anyone know why == “true” wouldn’t work when the same form
works for checking the column name against “Status”?

true == “true”
=> false

true.class
=> TrueClass

“true”.class
=> String

Nevermind my bad. Passing true to eql? in the proper way fixed my
problem.

However anyone know why == “true” wouldn’t work when the same form
works for checking the column name against “Status”?

On Mar 9, 11:06 am, “[email protected][email protected]

   <td>Open</td>

if ticket.send(column.name).eql?(“true”) always evaluates to false and
prints Closed.

I haven’t tested this, but I’m gonna guess that Ticket.status is a
boolean
field, but you’re comparing it to the string “true”. What happens if
you do:

ticket.send(column.name).eql?(true)

?

[email protected] wrote:

Nevermind my bad. Passing true to eql? in the proper way fixed my
problem.

However anyone know why == “true” wouldn’t work when the same form
works for checking the column name against “Status”?

“true” is the string with the letters t,r, u and e. Not in anyway
related to the boolean value true (except in the way that anything non
nil is true in ruby. the column’s name is however just a string.

if ticket.send(column.name)

would be enough

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs