Class: HandyForm::Builder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- HandyForm::Builder
- Defined in:
- lib/handy_form/builder.rb
Class Method Summary collapse
-
.model_name ⇒ Object
Allows this all handy_form_for objects to behave like the normal form builder in partials.
Instance Method Summary collapse
-
#build_label(method, options) ⇒ Object
(also: #label_for)
Build’s a label for the given ActiveModel method.
- #errors_for(method, options = {}) ⇒ Object
- #extract_handy_options!(options) ⇒ Object
- #hint(method, options = {}) ⇒ Object
Class Method Details
.model_name ⇒ Object
Allows this all handy_form_for objects to behave like the normal form builder in partials.
e.g., this will use the “_form.html.erb” partial in the current view directory.
<%= handy_form_for(@user) do |f| %>
<%= render :partial => f %>
<% end %>
53 54 55 |
# File 'lib/handy_form/builder.rb', line 53 def self.model_name @model_name ||= Struct.new(:partial_path).new("form") end |
Instance Method Details
#build_label(method, options) ⇒ Object Also known as: label_for
Build’s a label for the given ActiveModel method
When options = false, then no label is built When options is a string, then the value for the label is the string When options is a hash, hash will become the value for the label and all other options are passed into Rails’ label builder. Otherwise, the label is built off of the method.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/handy_form/builder.rb', line 68 def build_label(method, ) return "" if == false text = nil = {} text = method.to_s.humanize case when String text = when Hash if ![:text].blank? text = .delete(:text) end = end label(method, text, ) end |
#errors_for(method, options = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/handy_form/builder.rb', line 89 def errors_for(method, = {}) return "" unless object.errors[method.to_s].any? add_errors!(method, ) @template.error_tag([:error]) end |
#extract_handy_options!(options) ⇒ Object
57 58 59 |
# File 'lib/handy_form/builder.rb', line 57 def () .extract!(:error, :hint, :label, :wrapper, :input_first) end |
#hint(method, options = {}) ⇒ Object
95 96 97 |
# File 'lib/handy_form/builder.rb', line 95 def hint(method, = {}) @template.hint_tag() end |