Created
November 19, 2015 12:00
-
-
Save jurikern/259026cc80267931c1a4 to your computer and use it in GitHub Desktop.
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
class FormBuilder < ActionView::Helpers::FormBuilder | |
def text_field(attribute, options={}) | |
input_field(attribute, options) do | |
super | |
end | |
end | |
def password_field(attribute, options={}) | |
input_field(attribute, options) do | |
super | |
end | |
end | |
def check_box(attribute, options={}) | |
checked = options[:checked] || @object.send(attribute) | |
content_tag :div, class: 'field' do | |
content_tag :div, class: "ui#{checked ? ' checked' : ''} checkbox" do | |
super + label(attribute) | |
end | |
end | |
end | |
def select(attribute, choices=nil, options={}, html_options={}) | |
html_options[:class] = 'ui fluid dropdown' | |
content_tag :div, class: 'field' do | |
super | |
end | |
end | |
def submit(value, options={}) | |
options[:class] ||= 'ui fluid large green button' | |
super | |
end | |
def input_field(attribute, options={}, &block) | |
icon = options.delete(:icon) | |
label_name = options.delete(:label) | |
has_error = options.delete(:has_error) || @object.errors.has_key?(attribute) | |
label = label_name ? (label(attribute, label_name)) : raw('') | |
content_tag :div, class: "field#{has_error ? ' error' : ''}" do | |
if icon | |
label + content_tag(:div, class: 'ui left icon input') do | |
content_tag(:i, class: "#{icon} icon"){} + yield | |
end | |
else | |
label + yield | |
end | |
end | |
end | |
def method_missing(method, *args, &block) | |
@template.send(method, *args, &block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment