Skip to content

Instantly share code, notes, and snippets.

@ben-ole
Created February 23, 2017 09:29
Show Gist options
  • Save ben-ole/2125a63cbffa6a7e65944a2ae387e790 to your computer and use it in GitHub Desktop.
Save ben-ole/2125a63cbffa6a7e65944a2ae387e790 to your computer and use it in GitHub Desktop.
Foundation Switch Rails Form Helper
module FormHelper
class ActionView::Helpers::FormBuilder
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper
def switch(name, options = {})
@switch_id = "#{@object_name}_#{name}"
lbl(name,options) + container(name,options)
end
protected
def lbl(name, options)
label_tag(name, options[:label])
end
def check(name, options)
check_box name, options.merge({label: false, class: "switch-input"})
end
def container(name, options)
content_tag :div, check(name,options) + paddle, class: "switch"
end
def paddle
label_tag(@switch_id, "", class: "switch-paddle")
end
end
end
@ben-ole
Copy link
Author

ben-ole commented Feb 23, 2017

= f.switch :is_visible, label: "Visible"

bildschirmfoto 2017-02-23 um 10 34 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment