简体   繁体   English

想要向未登录的用户显示我的索引视图

[英]Want to show my index view to non-logged in users

So I don't apply an authenticate filter to my index action, but non-logged in users are still unable to access the index view because of this line: :class => "up_arrow #{current_user.votes_for(video).value == 1 ? 'voted' : 'unvoted' }" which determines whether or not a button should be styled depending on whether the user has voted on the element. 因此,我不会对索引操作应用身份验证筛选器,但是由于以下这一行,未登录的用户仍然无法访问索引视图:class => "up_arrow #{current_user.votes_for(video).value == 1 ? 'voted' : 'unvoted' }" ,它根据用户是否对元素进行投票来确定是否应设置按钮的样式。 However, since current_user is not defined for a logged out user, accessing the page brings up an error. 但是,由于未为注销用户定义current_user ,因此访问该页面将引发错误。 I don't want this to happen. 我不希望这种情况发生。 How can I fix this so that if current_user is nil, the user can still view the page, and the button receives the class 'unvoted' ? 我如何解决此问题,以便如果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.

相关问题 无论如何,对于未登录的用户,是否要使用public / index.html,但对于Rails 3,则要使用home#index进行登录? - Is there anyway to use a public/index.html for non-logged in users, but then home#index for logged in - in Rails 3? 从高层次来看,我如何允许未登录用户在我的应用程序中执行某些操作 - Rails 3 - From a high-level, how do I allow non-logged in users to do certain things in my app - Rails 3 路由根以显示登录用户的用户帖子和未登录的静态页面 - Routing root to display user's posts for logged in users and static page for non-logged in ActiveAdmin-允许未登录的用户查看但不能编辑资源 - ActiveAdmin - Allow non-logged-in users to view but not edit resources Rails-Pundit,如何仅显示未登录用户的控制器索引 - Rails - Pundit, how to show controller index only for not logged in users 如何在非设计视图中显示所有Devise用户 - how to show all Devise Users in a non-Devise View 如何设置登录用户和非登录用户的首页? - How to set a home page for logged in users and non logged in users? 在超时之前向用户显示消息 - Show users a message before they are logged out by timeout 我想将经过身份验证的用户的根目录设置为嵌套资源,即他们的仪表板,而不是将未经身份验证的用户用作根目录的home#index页面 - I want to set authenticated users' root to a nested resource, their dashboard, instead of the home#index page non-authenticated users use as root Rails和Authlogic。 显示当前登录的用户 - Rails and Authlogic. Show currently logged in users
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM