1

I have a script that executes (shows a modal) at 35 minutes (from inactivity) alerting the user they are about to be logged out. 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.
I tried adding erb to my coffee script file and just using an 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.

2
  • What's the error you're getting? Try changing the file to file_name.coffee.erb that will let you execute ruby in your coffee file. Commented Mar 17, 2013 at 16:37
  • Also, you can try adding a class to your body tag, i.e. user-logged-in, which you can add in your layouts template. And then make your javascript dependent on whether body.user-logged-in is present. It's not pretty but it would work. Commented Mar 17, 2013 at 16:39

1 Answer 1

3

In application.html.erb:

<%= javascript_include_tag "application" unless current_user.nil?  %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.