Skip to content

Instantly share code, notes, and snippets.

@rossshannon
Created January 18, 2016 00:10
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 rossshannon/048545e20260c05e1db5 to your computer and use it in GitHub Desktop.
Save rossshannon/048545e20260c05e1db5 to your computer and use it in GitHub Desktop.
Custom FormBuilder subclass to enable simple Ladda-enabled form buttons in Rails
class FormElementsBuilder < ActionView::Helpers::FormBuilder
# This is added to the normal form builder options, by adding
# <%= form_for(resource, as: resource_name, url: registration_path(resource_name), builder: FormElementsBuilder) do |f| %>
# then call it like this: <%= f.ladda_submit_button "Sign up" %>
def ladda_submit_button(label, *args)
options = args.extract_options!
behaviour = options[:behaviour] || 'expand-left'
@template.content_tag("button", {class: "ladda-button submit", 'data-style' => behaviour }) do
@template.content_tag("span", label.to_s.humanize, class: 'ladda-label')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment