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 %>
55 56 57 |
# File 'lib/handy_form/builder.rb', line 55 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.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/handy_form/builder.rb', line 70 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
91 92 93 94 95 |
# File 'lib/handy_form/builder.rb', line 91 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
59 60 61 |
# File 'lib/handy_form/builder.rb', line 59 def () .extract!(:error, :hint, :label, :wrapper, :input_first) end |
#hint(method, options = {}) ⇒ Object
97 98 99 |
# File 'lib/handy_form/builder.rb', line 97 def hint(method, = {}) @template.hint_tag() end |