簡體   English   中英

Rails link_to_remote什么也沒渲染,為什么?

[英]Rails link_to_remote rendering nothing, why?

RoR新手在這里。 使用Rails在Agile Web Dev的結尾處進行“播放時間”練習,第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似乎無所事事,b / c的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> 

感覺像我缺少真正明顯的東西。 我究竟做錯了什么?

使用<%= link_to_remote ... %>代替<% link_to_remote %> (假設您使用的是rails 2.x或更早版本)。

標記<% exp %>下的表達式只是求值,而不分配值。

如果要使用或顯示表達式的值,請使用“ =”符號,例如

<%= exp %>

只需將您的代碼更改為

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM