![](/img/trans.png)
[英]Is there anyway to use a public/index.html for non-logged in users, but then home#index for logged in - in Rails 3?
[英]Want to show my index view to non-logged in users
因此,我不會對索引操作應用身份驗證篩選器,但是由於以下這一行,未登錄的用戶仍然無法訪問索引視圖:class => "up_arrow #{current_user.votes_for(video).value == 1 ? 'voted' : 'unvoted' }"
,它根據用戶是否對元素進行投票來確定是否應設置按鈕的樣式。 但是,由於未為注銷用戶定義current_user
,因此訪問該頁面將引發錯誤。 我不希望這種情況發生。 我如何解決此問題,以便如果current_user
為nil,用戶仍然可以查看頁面,並且按鈕收到'unvoted'
類?
:class => "up_arrow #{
current_user && current_user.votes_for(video).value == 1 ? 'voted' : 'unvoted'
}"
class: "up_arrow #{current_user.try(:votes_for, video).try(:value) == 1 ? 'voted' : 'unvoted'}"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.