【发布时间】:2010-11-06 12:52:02
【问题描述】:
我正在为部分视图编写一些 Rails 代码,并且我希望它仅在有人已经登录到此处的站点时才显示评论字段。
如果页面被尚未成为站点成员的人查看,则应传入 shared/comment_not_logged_in 片段。
但是,我完全不知道为什么我不能运行相同的检查来决定页面是否应该在此处将类属性“missing_your_voice”添加到封闭的 div 元素:
<li class="user_submission_form bubble comment_form <% "missing_your_voice" if not current_user %>">
<% if current_user %>
<%= image_tag(current_user.avatar(:comment), :class => "profile_pic") %>
<% form_for [parent, Comment.new] do |f| %>
<%= render "comments/form", :f => f %>
<% end %>
<% else %>
<%= render :partial => 'shared/comment_not_logged_in' %>
<% end %>
</li>
同样的用法,"missing_your_voice" if not current_user 在 irb 中返回字符串,在控制台调试器中也是如此。
我在这里做错了什么?
【问题讨论】:
-
(拍自己的额头)天啊!太明显了!
标签: ruby-on-rails ruby views idioms