07 Dec 2010, 13:50
Generic-user-small

Chad Tipton (8 posts)

I am working through this example and it seems that @current_item isn’t getting passed to the format.js

In line_items_controller.rb

format.js   { @current_item = @line_item }

In _line_item.html.erb

<!-- START_HIGHLIGHT -->
<% if @current_item == line_item %>
<tr id="current_item">
<% elsif @current_item == nil %>
<tr id="nil">
<% else %>
<tr id="not_nill_not_current_item">
<% end %>

Finally, in the page source all of my table rows have an id of “nil”. Help?

07 Dec 2010, 15:48
Generic-user-small

Chad Tipton (8 posts)

Switching to

format.js { $current_item = @line_item }

works but I don’t necessarily want to have to use a global variable. Running on Windows XP.

ruby 1.9.2p0 (2010-08-18) [i385-mingw32]
Rails 3.0.3
Gem 1.3.7
09 Mar 2013, 13:38
Generic-user-small

Damon Henry (2 posts)

Bump …

I’m having the same issues as described above.

@current_item and @line_item are equal if set outside of the format.js block. The puts calls print out the objects to the command line. For some odd reason @current_item is nil in the _line_item.html.erb partial:

line_items_controller.rb

@current_item = @line_item 
puts "Line Item: #{@line_item}"
puts "Current Item: #{@current_item}"
format.js { @current_item}

</code>

_line_item.html.erb

<% if line_item == @current_item %>
<tr id="current_item">
    <% else %>
<tr>
<% end %>
    <td><%= line_item.quantity %></td>
    <td><%= line_item.product.title %></td>
    <td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
</tr>

Environment: ruby 2.1.0dev (2013-02-27) [x86_64-darwin11.4.2] Rails 4.0.0.beta1 Gem 1.8.25

09 Mar 2013, 14:25
Samr_small_pragsmall

Sam Ruby (584 posts)

When I copy/paste your lines, I see the following[1] on my console window:

Line Item: #< LineItem:0x007fed15d4e810 >
Current Item: #< LineItem:0x007fed15d4e810 >

Environment:

$ ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.1]
$ rails -v
Rails 4.0.0.beta1
$ gem -v
2.0.2

1: note spaces added to prevent this from being interpreted as markup

10 Mar 2013, 17:38
Generic-user-small

Damon Henry (2 posts)

Thanks Sam. Updating to the latest RubyGem solved the problem.

  You must be logged in to comment