![](/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.