Hello all. I’m a noob at Ruby on Rails, only started learning a few days
ago, but I’m loving it so far. I do have a few years experience with
PHP, ASP, MySQL, etc., so I’m not totally clueless, though.
Anyway, I’m having trouble with something that should be fairly trivial:
I have an ‘if’ statement that is supposed to print out a table row if a
vriable is either nil, or matches another specific value (like the
Rolling with Rails tutorial example). Unfortunately, it only works
halfway. It will print the table rows if the variable is nil, but if the
variable has any valu in it at all, it prints nothing, even when it
matches the other value. I’ve been banging my head against this for
about an hour now, and I think it’s one of those things where I can’t
see it because it’s too simple, so I’m hoping that maybe one of you can
tell me what’s wrong by looking at the code? Here’s the code I’m using:
<% @carttransactions.each do |carttransaction| %>
<%= @cartno %><%= carttransaction.cart.id %>
<% if (@cartno == nil ) || (@cartno == carttransaction.cart.id ) %>
When I access the page with
‘http://localhost:3000/carttransaction/list’, it displays the table rows
perfectly. However, if I try
‘http://localhost:3000/carttransaction/list?cartno=1’, it displays none
of the rows, not even the ones where ‘carttransaction.cart.id’ equals 1.
You’ll notice the line
‘<%= @cartno %><%= carttransaction.cart.id %>’
up there, I put that in to make sure that, indeed, both vars were there
and their values matched, and the page prints them both out and shows
that @cartno is, indeed, receiving the value from the URL, and that the
other one also has its value… so, any ideas at all? I’m stumped.