Rails link_to_remote 没有渲染任何内容,为什么?
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 + "×",
: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>
感觉我错过了一些非常明显的东西。我做错了什么?
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.price) %></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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标签
<% exp %>
下的表达式仅被求值,而不是赋值。如果您想使用或显示表达式的值,只需使用“=”符号,例如
只需将代码更改为
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
Just change You code to
使用
<%= link_to_remote ... %>
而不是<% link_to_remote %>
(假设您使用的是 Rails 2.x 或以前的版本)。Use
<%= link_to_remote ... %>
instead of<% link_to_remote %>
(assuming you are using rails 2.x or previous versions).