9

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

2 Answers 2

22
<% if @cart.total_items ==1 %>
  $('#cart').show(2000);
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

1

@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

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.