avoid button_to action with javascript in rails -


i making shopping cart , user can add products cart when signed in.

i created javascript when user clicks button "add cart", evaluates if signed in , displays message, need stop button action because cause problem render action. thanks. here code

<%=button_to 'add cart',line_items_path(:product_id => product.id),:onclick=>"javascript:is_user()"%> 

you try this:

<% if current_user.present? %>   <%= button_to 'add cart',line_items_path(:product_id => product.id) %> <% else %>   <%= button_to 'login add cart', '' %> <% end %> 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -