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
Post a Comment