RoR newbie here. Working the "play time" exercises at the end of Agile Web Dev with Rails, chapter 9. Can't get link_to_remote to generate a link for me in a partial. My store_cart_item.html.erb partial looks like this:
<% if cart_item == @current_item then %>
<tr id="current_item">
<% else %>
<tr>
<% end %>
<td>
<!-- stuck here, trying to get a link to decrement the quantity, but it doesn't
even show a link, I also tried nesting a link_to in form_remote_tag which
at least displayed link but didn't call the remove_from_cart action -->
<% link_to_remote cart_item.quantity.to_s + "×",
:update => "cart",
:url => {:action => "remove_from_cart", :id => cart_item.product} %>
</td>
<td><%= h cart_item.title %></td>
<td class="item-price"><%= number_to_currency(cart_item.pri开发者_运维百科ce) %></td>
</tr>
In the browser, link_to_remote appears to be doing nothing, b/c the html output looks like this:
<tr>
<td>
<!-- stuck here, trying to get a stupid link to decrement the quantity, doesn't even show link
also tried nesting it in form_remote_tag which at least displayed link but didn't call the
remove_from_cart action -->
</td>
<td>Agile Web Development with Rails</td>
<td class="item-price">$68.85</td>
</tr>
Feels like I am missing something really obvious. What am I doing wrong?
Expression under the tag <% exp %>
are just evaluated, not assign the value.
And If you want to use or display the value of expression just use "=" sign like
<%= exp %>
Just change You code to
<%= link_to_remote cart_item.quantity.to_s + "×",
:update => "cart",
:url => {:action => "remove_from_cart", :id => cart_item.product} %>
Use <%= link_to_remote ... %>
instead of <% link_to_remote %>
(assuming you are using rails 2.x or previous versions).
精彩评论