John
John

Reputation: 1323

How to add JavaScript based on some ruby conditionality?

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 %>

Upvotes: 0

Views: 42

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

<% if current_user.role == "User" %>
  <%= render js: "alert('Hello, world!')" %>
  <%= render 'path/to/file.js' %>
<% end %>

Upvotes: 1

Related Questions