small medium large xlarge

Generic-user-small
08 May 2017, 17:18
Francesco mari (4 posts)

Since I have “Delete item” and “Decrement quantity” buttons on the _line_item.html.erb partial (which is used also for rendering the cart), and I don’t want to show those buttons on the “received” html template I use for the order_mailer, I’m checking the ancestors of the current controller. Could it be improved? Do you have any observations?

app/views/line_items/_line_item.html.erb

<% if line_item == @current_item %>
<tr id="current_item">
<% else %>
<tr>
<% end %>
  <% if controller.class.ancestors.include?(ApplicationController) %>
    <td><%= button_to("X", line_item, method: :delete) %></td>
    <td><%= button_to "V", decrement_line_item_path(line_item), method: :post, remote: true %></td>
  <% 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>
</tr>
You must be logged in to comment