0

RoR初心者はこちら。Railsを使用したアジャイルWeb開発の最後の第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 /chtml出力は次のようになります。

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

本当に明らかな何かが欠けているような気がします。私は何が間違っているのですか?

4

2 に答える 2

2

<%= link_to_remote ... %>代わりに使用<% link_to_remote %>してください(rails 2.xまたは以前のバージョンを使用していると仮定します)。

于 2010-07-14T06:06:53.643 に答える
2

タグの下の式<% exp %>は評価されるだけで、値は割り当てられません。

また、式の値を使用または表示する場合は、「=」記号を使用します。

<%= exp %>

コードを次のように変更するだけです

<%= link_to_remote cart_item.quantity.to_s + "&times;",
                :update => "cart",
                :url => {:action => "remove_from_cart", :id => cart_item.product} %>
于 2010-07-14T06:26:19.463 に答える