Skip to content

Instantly share code, notes, and snippets.

@carlosantoniodasilva
Created November 21, 2010 23:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosantoniodasilva/709301 to your computer and use it in GitHub Desktop.
Save carlosantoniodasilva/709301 to your computer and use it in GitHub Desktop.
SimpleForm submit with cancel link example
module SimpleForm
class FormBuilder < ActionView::Helpers::FormBuilder
# You can just override the default submit button and add the functionality.
#
# Simple usage:
# f.button :submit 'Send!', :cancel_link => root_path
#
def submit(*args)
cancel_link = args.last.is_a?(Hash) && args.last.delete(:cancel_link)
submit_button = super
submit_button << @template.link_to('cancel', cancel_link) if cancel_link
submit_button
end
# Or you can just create your own helpers to handle that.
#
def submit_with_cancel(*args)
# Do whatever you want here...
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment