small medium large xlarge

23 Nov 2011, 17:38
Thomas Foote (2 posts)

I’m working my way through the book, and chose to implement the playtime task to add a button to decrement the quantity of a line_item in the cart. This all worked well until getting to chapter 13 and sending emails using the same html partial for the line_item.

When running the functional test to send the shipped email, i get the following error:

ERROR shipped (0.02s) ActionView::Template::Error: undefined method `protect_against_forgery?’ for #<#:0x007fc6eed9da48>

My line_item partial looks like this:

<% if line_item == @current_item %>
	<tr id="current_item">
<% else %>
<% end %>
<td><%= line_item.quantity %>&times;</td>
<td><%= line_item.product.title %></td>
<td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
<td><%= button_to 'x', decrement_line_item_path(line_item), method: :post, remote: true %></td>

and if I remove the button the test passes. My question is; is it possible to specify elements to only appear in certain functions, or is there a better way of doing this?

Thanks, Tom

30 Apr 2012, 12:17
Chris James (1 post)


While I’m sure you’ve moved on from this, I found your post while searching for an answer, so for future searchers:

You can resolve this problem by making the decrement button’s inclusion conditional on there not being a current order.

<% if @order.nil? %>
  <%= button_to 'Remove', remove_line_item_path(line_item), remote: true %>
<% end %>

Et voila! Now the decrement button disappears both for the email (which uses @order to populate the message), and checkout (which uses @order for obvious reasons).

You must be logged in to comment