Skip to content

Instantly share code, notes, and snippets.

@niklas
Created April 20, 2011 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklas/931508 to your computer and use it in GitHub Desktop.
Save niklas/931508 to your computer and use it in GitHub Desktop.
get real buttons in forms that is stylable
# now you can use
# form.button :submit
# to get a real button that is stylable
class SimpleForm::FormBuilder
def submit_button(title=nil, options={}, &block)
title, options = nil, title if title.is_a?(Hash)
title ||= submit_default_value
options[:type] = 'submit'
template.add_class_to_html_options(options, 'submit')
template.content_tag(:button, title, options)
end
def preview_button(options={}, &block)
title = I18n.t('helpers.preview')
options[:type] = 'submit'
options[:name] = 'preview'
template.add_class_to_html_options(options, 'preview')
template.content_tag(:button, title, options)
end
def cancel_button(options={})
title = I18n.t('helpers.cancel')
target = options.delete(:url) || object
template.add_class_to_html_options(options, 'button')
template.add_class_to_html_options(options, 'warning')
template.add_class_to_html_options(options, 'cancel')
template.link_to(title, target, options)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment