0

I want to add some JavaScript based on some ruby conditionality. How can i do that?

For example

<%= if current_user.role == "User" %>
  Adding some JavaScript here
<% else %>
3
  • What framework are you using? Commented Mar 24, 2017 at 9:31
  • I am using Ruby on Rails application Commented Mar 24, 2017 at 9:38
  • See this question, Put your JS codes in <script> tag. See this question stackoverflow.com/questions/17795053/… Commented Mar 24, 2017 at 9:42

1 Answer 1

1
<% if current_user.role == "User" %>
  <%= render js: "alert('Hello, world!')" %>
  <%= render 'path/to/file.js' %>
<% end %>
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.