Rails link_to_remote ничего не рендерит, почему?

RoR новичок здесь. Выполнение упражнений "время воспроизведения" в конце Agile Web Dev с Rails, глава 9. Не удается получить link_to_remote для генерации ссылки для меня в частичном. Мой частично store_cart_item.html.erb выглядит так:

<% 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 + "&times;",
                :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.price) %></td>
</tr>

В браузере link_to_remote, похоже, ничего не делает, т.к. вывод html выглядит следующим образом:

<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> 

Чувствуется, что мне не хватает чего-то действительно очевидного. Что я делаю неправильно?

2 ответа

Решение

Выражение под тегом <% exp %> только оцениваются, а не присваивают значение.

И если вы хотите использовать или отобразить значение выражения, просто используйте знак "=", как

<%= exp %>

Просто измените свой код на

<%= link_to_remote cart_item.quantity.to_s + "&times;",
                :update => "cart",
                :url => {:action => "remove_from_cart", :id => cart_item.product} %>

Использование <%= link_to_remote ... %> вместо <% link_to_remote %> (при условии, что вы используете rails 2.x или предыдущие версии).

Другие вопросы по тегам