Created
February 23, 2017 09:29
-
-
Save ben-ole/2125a63cbffa6a7e65944a2ae387e790 to your computer and use it in GitHub Desktop.
Foundation Switch Rails Form Helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
= f.switch :is_visible, label: "Visible"