Reputation: 11197
As far as I can tell button_to is for submitting a form. Is there something in rails dedicated for buttons that just run some javascript on the client without sending anything to the server?
Upvotes: 2
Views: 2939
Reputation: 3156
Please try this:
you can call javascript function using onclick. It will not submit a form.
<%= submit_tag "Test me!", :type => 'button', :onclick => 'alert("It works!")' %>
Upvotes: 0
Reputation: 5974
If you want to run only javascript on client side, you can add plain html button and call some function to run your required javascript, by binding an event to that button. You dont need to use rails code at all.
Upvotes: 3
Reputation: 23678
That has nothing to do with rails but rather HTML.
You can always place normal HTML markup (like a <button>
or a <a>
on the form and make it trigger some action in JavaScript)
Sample:
<%= form_for(@post) do |f| %>
...
<button id="clicktrigger">Click Me!</button>
<% end %>
Upvotes: 0