Class: Effective::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- Effective::FormBuilder
- Defined in:
- app/models/effective/form_builder.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#disabled ⇒ Object
Returns the value of attribute disabled.
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#readonly ⇒ Object
Returns the value of attribute readonly.
-
#remote ⇒ Object
Returns the value of attribute remote.
-
#template ⇒ Object
Returns the value of attribute template.
Instance Method Summary collapse
- #article_editor(name, options = {}, &block) ⇒ Object
- #check_box(name, options = {}) ⇒ Object
- #checks(name, choices = nil, *args) ⇒ Object
- #ck_editor(name, options = {}, &block) ⇒ Object
- #clear(name = 'Clear', options = {}) ⇒ Object
- #date_field(name, options = {}) ⇒ Object
- #datetime_field(name, options = {}) ⇒ Object
- #delete(name = 'Remove', url = nil, options = {}, &block) ⇒ Object
- #editor(name, options = {}, &block) ⇒ Object
- #email_cc_field(name, options = {}) ⇒ Object
- #email_field(name, options = {}) ⇒ Object
- #error(name = nil, options = {}) ⇒ Object (also: #errors)
- #file_field(name, options = {}) ⇒ Object
- #float_field(name, options = {}) ⇒ Object
- #form_group(name = nil, options = {}, &block) ⇒ Object
-
#has_many(name, collection = nil, options = {}, &block) ⇒ Object
Has Many.
- #hidden_field(name = nil, options = {}) ⇒ Object
-
#hide_if(*args, &block) ⇒ Object
Logics.
-
#initialize(object_name, object, template, options) ⇒ FormBuilder
constructor
A new instance of FormBuilder.
- #integer_field(name, options = {}) ⇒ Object
- #number_field(name, options = {}) ⇒ Object
- #number_text_field(name, options = {}) ⇒ Object
- #password_field(name, options = {}) ⇒ Object
- #percent_field(name, options = {}) ⇒ Object
- #phone_field(name, options = {}) ⇒ Object (also: #tel_field, #telephone_field)
- #price_field(name, options = {}) ⇒ Object
- #radios(name, choices = nil, *args) ⇒ Object
-
#remote_link_to(name, url, options = {}, &block) ⇒ Object
This is gonna be a post?.
- #reset(name = 'Reset', options = {}) ⇒ Object
- #rich_text_area(name, options = {}) ⇒ Object
- #save(name = 'Save', options = {}) ⇒ Object
- #search_field(name, options = {}) ⇒ Object
- #select(name, choices = nil, *args) ⇒ Object
- #select_or_text(name, name_text, choices = nil, *args) ⇒ Object
- #show_if(*args, &block) ⇒ Object
- #show_if_any(*args, &block) ⇒ Object
- #static_field(name, options = {}, &block) ⇒ Object
- #submit(name = 'Save', options = {}, &block) ⇒ Object
- #super_hidden_field ⇒ Object
- #super_number_field ⇒ Object
- #super_text_area ⇒ Object
- #super_text_field ⇒ Object
- #text_area(name, options = {}) ⇒ Object
- #text_field(name, options = {}) ⇒ Object
- #time_field(name, options = {}) ⇒ Object
- #time_zone_select(name, options = {}) ⇒ Object
- #url_field(name, options = {}) ⇒ Object
Constructor Details
#initialize(object_name, object, template, options) ⇒ FormBuilder
Returns a new instance of FormBuilder.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/models/effective/form_builder.rb', line 10 def initialize(object_name, object, template, ) @template = template @layout = (.delete(:layout) || :vertical).to_sym @action = .delete(:action) @readonly = .delete(:readonly) @disabled = .delete(:disabled) @remote = [:remote] super end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
6 7 8 |
# File 'app/models/effective/form_builder.rb', line 6 def action @action end |
#disabled ⇒ Object
Returns the value of attribute disabled.
6 7 8 |
# File 'app/models/effective/form_builder.rb', line 6 def disabled @disabled end |
#layout ⇒ Object
Returns the value of attribute layout.
6 7 8 |
# File 'app/models/effective/form_builder.rb', line 6 def layout @layout end |
#readonly ⇒ Object
Returns the value of attribute readonly.
6 7 8 |
# File 'app/models/effective/form_builder.rb', line 6 def readonly @readonly end |
#remote ⇒ Object
Returns the value of attribute remote.
6 7 8 |
# File 'app/models/effective/form_builder.rb', line 6 def remote @remote end |
#template ⇒ Object
Returns the value of attribute template.
6 7 8 |
# File 'app/models/effective/form_builder.rb', line 6 def template @template end |
Instance Method Details
#article_editor(name, options = {}, &block) ⇒ Object
27 28 29 |
# File 'app/models/effective/form_builder.rb', line 27 def article_editor(name, = {}, &block) Effective::FormInputs::ArticleEditor.new(name, , builder: self).to_html(&block) end |
#check_box(name, options = {}) ⇒ Object
36 37 38 39 40 41 42 |
# File 'app/models/effective/form_builder.rb', line 36 def check_box(name, = {}) Effective::FormInputs::CheckBox.new(name, , builder: self).to_html { checked_value = .fetch(:checked_value, '1') unchecked_value = .fetch(:unchecked_value, '0') super(name, .except(:checked_value, :unchecked_value), checked_value, unchecked_value) } end |
#checks(name, choices = nil, *args) ⇒ Object
44 45 46 47 |
# File 'app/models/effective/form_builder.rb', line 44 def checks(name, choices = nil, *args) = args..merge!(collection: choices) Effective::FormInputs::Checks.new(name, , builder: self).to_html end |
#ck_editor(name, options = {}, &block) ⇒ Object
49 50 51 |
# File 'app/models/effective/form_builder.rb', line 49 def ck_editor(name, = {}, &block) Effective::FormInputs::CkEditor.new(name, , builder: self).to_html(&block) end |
#clear(name = 'Clear', options = {}) ⇒ Object
31 32 33 34 |
# File 'app/models/effective/form_builder.rb', line 31 def clear(name = 'Clear', = {}) ( = name; name = 'Clear') if name.kind_of?(Hash) Effective::FormInputs::Clear.new(name, , builder: self).to_html end |
#date_field(name, options = {}) ⇒ Object
53 54 55 |
# File 'app/models/effective/form_builder.rb', line 53 def date_field(name, = {}) Effective::FormInputs::DateField.new(name, , builder: self).to_html { super(name, ) } end |
#datetime_field(name, options = {}) ⇒ Object
57 58 59 |
# File 'app/models/effective/form_builder.rb', line 57 def datetime_field(name, = {}) Effective::FormInputs::DatetimeField.new(name, , builder: self).to_html { super(name, ) } end |
#delete(name = 'Remove', url = nil, options = {}, &block) ⇒ Object
61 62 63 64 |
# File 'app/models/effective/form_builder.rb', line 61 def delete(name = 'Remove', url = nil, = {}, &block) [:href] ||= url Effective::FormInputs::Delete.new(name, , builder: self).to_html(&block) end |
#editor(name, options = {}, &block) ⇒ Object
66 67 68 |
# File 'app/models/effective/form_builder.rb', line 66 def editor(name, = {}, &block) Effective::FormInputs::Editor.new(name, , builder: self).to_html(&block) end |
#email_cc_field(name, options = {}) ⇒ Object
74 75 76 |
# File 'app/models/effective/form_builder.rb', line 74 def email_cc_field(name, = {}) Effective::FormInputs::EmailCcField.new(name, , builder: self).to_html end |
#email_field(name, options = {}) ⇒ Object
70 71 72 |
# File 'app/models/effective/form_builder.rb', line 70 def email_field(name, = {}) Effective::FormInputs::EmailField.new(name, , builder: self).to_html { super(name, ) } end |
#error(name = nil, options = {}) ⇒ Object Also known as: errors
78 79 80 |
# File 'app/models/effective/form_builder.rb', line 78 def error(name = nil, = {}) Effective::FormInputs::ErrorField.new(name, , builder: self).to_html() end |
#file_field(name, options = {}) ⇒ Object
83 84 85 |
# File 'app/models/effective/form_builder.rb', line 83 def file_field(name, = {}) Effective::FormInputs::FileField.new(name, , builder: self).to_html { super(name, ) } end |
#float_field(name, options = {}) ⇒ Object
87 88 89 |
# File 'app/models/effective/form_builder.rb', line 87 def float_field(name, = {}) Effective::FormInputs::FloatField.new(name, , builder: self).to_html end |
#form_group(name = nil, options = {}, &block) ⇒ Object
91 92 93 |
# File 'app/models/effective/form_builder.rb', line 91 def form_group(name = nil, = {}, &block) Effective::FormInputs::FormGroup.new(name, , builder: self).to_html(&block) end |
#has_many(name, collection = nil, options = {}, &block) ⇒ Object
Has Many
213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'app/models/effective/form_builder.rb', line 213 def has_many(name, collection = nil, = {}, &block) association = object.class.reflect_on_all_associations.find { |a| a.name == name } raise("expected #{object.class.name} to has_many :#{name}") if association.blank? = (object.class. || {})[name] raise("expected #{object.class.name} to accepts_nested_attributes_for :#{name}") if .blank? = collection if collection.kind_of?(Hash) .merge!(collection: collection) if collection && !collection.kind_of?(Hash) Effective::FormInputs::HasMany.new(name, , builder: self).to_html(&block) end |
#hidden_field(name = nil, options = {}) ⇒ Object
95 96 97 |
# File 'app/models/effective/form_builder.rb', line 95 def hidden_field(name = nil, = {}) Effective::FormInputs::HiddenField.new(name, , builder: self).to_html end |
#hide_if(*args, &block) ⇒ Object
Logics
200 201 202 |
# File 'app/models/effective/form_builder.rb', line 200 def hide_if(*args, &block) Effective::FormLogics::HideIf.new(*args, builder: self).to_html(&block) end |
#integer_field(name, options = {}) ⇒ Object
99 100 101 |
# File 'app/models/effective/form_builder.rb', line 99 def integer_field(name, = {}) Effective::FormInputs::IntegerField.new(name, , builder: self).to_html end |
#number_field(name, options = {}) ⇒ Object
117 118 119 |
# File 'app/models/effective/form_builder.rb', line 117 def number_field(name, = {}) Effective::FormInputs::NumberField.new(name, , builder: self).to_html { super(name, ) } end |
#number_text_field(name, options = {}) ⇒ Object
121 122 123 |
# File 'app/models/effective/form_builder.rb', line 121 def number_text_field(name, = {}) Effective::FormInputs::NumberTextField.new(name, , builder: self).to_html end |
#password_field(name, options = {}) ⇒ Object
125 126 127 |
# File 'app/models/effective/form_builder.rb', line 125 def password_field(name, = {}) Effective::FormInputs::PasswordField.new(name, , builder: self).to_html { super(name, ) } end |
#percent_field(name, options = {}) ⇒ Object
129 130 131 |
# File 'app/models/effective/form_builder.rb', line 129 def percent_field(name, = {}) Effective::FormInputs::PercentField.new(name, , builder: self).to_html end |
#phone_field(name, options = {}) ⇒ Object Also known as: tel_field, telephone_field
133 134 135 |
# File 'app/models/effective/form_builder.rb', line 133 def phone_field(name, = {}) Effective::FormInputs::PhoneField.new(name, , builder: self).to_html { super(name, ) } end |
#price_field(name, options = {}) ⇒ Object
139 140 141 |
# File 'app/models/effective/form_builder.rb', line 139 def price_field(name, = {}) Effective::FormInputs::PriceField.new(name, , builder: self).to_html { super(name, ) } end |
#radios(name, choices = nil, *args) ⇒ Object
168 169 170 171 |
# File 'app/models/effective/form_builder.rb', line 168 def radios(name, choices = nil, *args) = args..merge!(collection: choices) Effective::FormInputs::Radios.new(name, , builder: self).to_html end |
#remote_link_to(name, url, options = {}, &block) ⇒ Object
This is gonna be a post?
104 105 106 107 |
# File 'app/models/effective/form_builder.rb', line 104 def remote_link_to(name, url, = {}, &block) [:href] ||= url Effective::FormInputs::RemoteLinkTo.new(name, , builder: self).to_html(&block) end |
#reset(name = 'Reset', options = {}) ⇒ Object
173 174 175 176 |
# File 'app/models/effective/form_builder.rb', line 173 def reset(name = 'Reset', = {}) ( = name; name = 'Reset') if name.kind_of?(Hash) Effective::FormInputs::Reset.new(name, , builder: self).to_html end |
#rich_text_area(name, options = {}) ⇒ Object
109 110 111 |
# File 'app/models/effective/form_builder.rb', line 109 def rich_text_area(name, = {}) Effective::FormInputs::RichTextArea.new(name, , builder: self).to_html { super(name, ) } end |
#save(name = 'Save', options = {}) ⇒ Object
143 144 145 146 |
# File 'app/models/effective/form_builder.rb', line 143 def save(name = 'Save', = {}) ( = name; name = 'Save') if name.kind_of?(Hash) Effective::FormInputs::Save.new(name, , builder: self).to_html { super(name, ) } end |
#search_field(name, options = {}) ⇒ Object
113 114 115 |
# File 'app/models/effective/form_builder.rb', line 113 def search_field(name, = {}) Effective::FormInputs::SearchField.new(name, , builder: self).to_html { super(name, ) } end |
#select(name, choices = nil, *args) ⇒ Object
148 149 150 151 |
# File 'app/models/effective/form_builder.rb', line 148 def select(name, choices = nil, *args) = args..merge!(collection: choices) Effective::FormInputs::Select.new(name, , builder: self).to_html end |
#select_or_text(name, name_text, choices = nil, *args) ⇒ Object
153 154 155 156 |
# File 'app/models/effective/form_builder.rb', line 153 def select_or_text(name, name_text, choices = nil, *args) = args..merge!(name_text: name_text, collection: choices) Effective::FormInputs::SelectOrText.new(name, , builder: self).to_html end |
#show_if(*args, &block) ⇒ Object
204 205 206 |
# File 'app/models/effective/form_builder.rb', line 204 def show_if(*args, &block) Effective::FormLogics::ShowIf.new(*args, builder: self).to_html(&block) end |
#show_if_any(*args, &block) ⇒ Object
208 209 210 |
# File 'app/models/effective/form_builder.rb', line 208 def show_if_any(*args, &block) Effective::FormLogics::ShowIfAny.new(*args, builder: self).to_html(&block) end |
#static_field(name, options = {}, &block) ⇒ Object
163 164 165 166 |
# File 'app/models/effective/form_builder.rb', line 163 def static_field(name, = {}, &block) = { value: } if .kind_of?(String) Effective::FormInputs::StaticField.new(name, , builder: self).to_html(&block) end |
#submit(name = 'Save', options = {}, &block) ⇒ Object
158 159 160 161 |
# File 'app/models/effective/form_builder.rb', line 158 def submit(name = 'Save', = {}, &block) ( = name; name = 'Save') if name.kind_of?(Hash) Effective::FormInputs::Submit.new(name, , builder: self).to_html(&block) end |
#super_hidden_field ⇒ Object
25 |
# File 'app/models/effective/form_builder.rb', line 25 alias_method :super_hidden_field, :hidden_field |
#super_number_field ⇒ Object
22 |
# File 'app/models/effective/form_builder.rb', line 22 alias_method :super_number_field, :number_field |
#super_text_area ⇒ Object
24 |
# File 'app/models/effective/form_builder.rb', line 24 alias_method :super_text_area, :text_area |
#super_text_field ⇒ Object
23 |
# File 'app/models/effective/form_builder.rb', line 23 alias_method :super_text_field, :text_field |
#text_area(name, options = {}) ⇒ Object
178 179 180 |
# File 'app/models/effective/form_builder.rb', line 178 def text_area(name, = {}) Effective::FormInputs::TextArea.new(name, , builder: self).to_html { super(name, ) } end |
#text_field(name, options = {}) ⇒ Object
182 183 184 |
# File 'app/models/effective/form_builder.rb', line 182 def text_field(name, = {}) Effective::FormInputs::TextField.new(name, , builder: self).to_html { super(name, ) } end |
#time_field(name, options = {}) ⇒ Object
186 187 188 |
# File 'app/models/effective/form_builder.rb', line 186 def time_field(name, = {}) Effective::FormInputs::TimeField.new(name, , builder: self).to_html { super(name, ) } end |
#time_zone_select(name, options = {}) ⇒ Object
190 191 192 193 |
# File 'app/models/effective/form_builder.rb', line 190 def time_zone_select(name, = {}) opts = .merge(collection: Effective::FormInputs::TimeZoneSelect.time_zone_collection) Effective::FormInputs::TimeZoneSelect.new(name, opts, builder: self).to_html end |
#url_field(name, options = {}) ⇒ Object
195 196 197 |
# File 'app/models/effective/form_builder.rb', line 195 def url_field(name, = {}) Effective::FormInputs::UrlField.new(name, , builder: self).to_html { super(name, ) } end |