简体   繁体   English

如果current_user logged_in,Rails只执行javascript

[英]Rails only execute javascript if current_user logged_in

I have a script that executes (shows a modal) at 35 minutes (from inactivity) alerting the user they are about to be logged out. 我有一个脚本在35分钟(从不活动状态)执行(显示模态),提醒用户他们即将被注销。 If they click a button in that modal they can remain logged in or another button to log out. 如果他们单击该模式中的按钮,他们可以保持登录状态或其他按钮以注销。 The problem is the script is running whether a user is logged in or not. 问题是无论用户是否登录,脚本都在运行。 How can I limit the script to only load and be run if there is a current_user. 如果有current_user,如何将脚本限制为仅加载并运行。
I tried adding erb to my coffee script file and just using an if logged_in? 我尝试将erb添加到我的咖啡脚本文件中并使用if logged_in? block, but I get errors when trying to include the helper in that file. 阻止,但尝试在该文件中包含帮助程序时出错。 And, this seems like an awful way to do it. 而且,这似乎是一种糟糕的方式。

application.html.erb

<%= javascript_include_tag "application" unless current_user.nil?  %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM