Rails form multiple submits to multiple controller actions
Posted 11 September 2006 @ 4pm | Tagged thoughts
Say you have a form that can have multiple actions. For example, you have a list of emails and you need to do the following: confirm, resend confirmation, make primary (think Paypal). I’ve created a simple helper that just sets the form’s action on the button’s click event so the form can get submitted to different actions on the controller:
# lang ruby
def submit_tag_to_action(value, action, options={})
submit_tag(value, options.merge!(:onclick => "this.form.action='#{action}'"))
end
### usage:
submit_tag_to_action "myButton", "myAction"



3 Comments