我正在爲部分視圖編寫一些Rails代碼,並且我希望它只顯示註釋字段,如果有人已經登錄到網站在這裏。什麼是在軌道中的視圖中的html元素添加類屬性的最簡潔的方法
如果網頁是由人誰是不是網站的會員還看,shared/comment_not_logged_in
片段應該傳入。
不過,我完全難住了,爲什麼我不能運行相同的檢查,以決定是否頁應該class屬性「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字符串,並在控制檯調試器。
我在這裏做錯了什麼?
(拍拍自己的額頭) D'oh! 非常明顯! – 2009-06-28 20:10:34