Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I need to do something like shown below; add a jquery effect depending on the value of an instance object in rails
("$('#cart').show(2000);") if @cart.total_items ==1
<% if @cart.total_items ==1 %> $('#cart').show(2000); <% end %>
Add a comment
@xdazz answer is right , but i used to use the conditional statements as follows
var mycount = <%= @cart.total_items %> if (mycount == 1){ $("#cart").show(2000) }
The reason i use mostly conditional statements in javascript (in js.erb file) is because this seems easy to handle
conditional statements
Required, but never shown
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.
Explore related questions
See similar questions with these tags.