我是Rails的新手,和其他很多人一样,我也是通过Hartl的Rails教程学习Rails的。但是在练习5,第10章(使用部分词来消除重复),我完全被塞住了,我想要清晰地继续下去。使用堆栈溢出,我找到了一个解决方案,但它对我不起作用。在我的例子中,“删除”链接不出现。我的档案:
app/views/shared/_feed_item.html.erb
<li id="<%= feed_item.id %>">
<%= link_to gravatar_for(feed_item.user), feed_item.user %>
<span class="user">
<%= link_to feed_item.user.name, feed_item.user %>
</span>
<span class="content"><%= feed_item.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(feed_item.created_at) %> ago.
</span>
<% if current_user?(feed_item.user) %>
<% render partial: 'shared/delete_link', locals: { object: feed_item } %>
<% end %>
</li>app/views/microposts/_micropost.html.erb
<li>
<span class="content"><%= micropost.content %></span>
<span class="timestamp">
Posted <%= time_ago_in_words(micropost.created_at) %> ago.
</span>
<% if current_user?(micropost.user) %>
<% render partial: 'shared/delete_link', locals: { object: micropost } %>
<% end %>
</li>app/views/shared/_delete_link.html.erb
<%= link_to "delete", object, method: :delete,
data: { confirm: "You sure?" },
title: object.content %>我不明白为什么“删除”链接不呈现。条件current_user?成功地执行..。就好像<% render partial: 'shared/delete_link', locals: { object: feed_item } %>根本不存在一样。零利润。如果有人能告诉我这个案子,我会非常感激的。谢谢。
发布于 2013-03-13 08:27:57
将<% render partial: 'shared/delete_link', locals: { object: feed_item } %>更改为<%= render partial: 'shared/delete_link', locals: { object: feed_item } %>
发布于 2013-10-07 06:35:50
我们可以通过削减partial:和locals:来减少这一点。
也就是说,这也适用于:<%= render 'shared/delete_link', object: feed_item %>
https://stackoverflow.com/questions/15380162
复制相似问题