Class: AnyView::Helpers::FormBuilder::AbstractFormBuilder
- Inherits:
-
Object
- Object
- AnyView::Helpers::FormBuilder::AbstractFormBuilder
- Defined in:
- lib/any_view/form_builder/abstract_form_builder.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#view_context ⇒ Object
Returns the value of attribute view_context.
Instance Method Summary collapse
-
#check_box(field, options = {}) ⇒ Object
f.check_box :remember_me, :value => ‘true’, :uncheck_value => ‘0’.
-
#error_messages(options = {}) ⇒ Object
f.error_messages.
-
#file_field(field, options = {}) ⇒ Object
f.file_field :photo, :class => ‘avatar’.
-
#hidden_field(field, options = {}) ⇒ Object
f.hidden_field :session_id, :value => “45”.
-
#image_submit(source, options = {}) ⇒ Object
f.simage_submitubmit “buttons/submit.png”, :class => ‘large’.
-
#initialize(view_context, object) ⇒ AbstractFormBuilder
constructor
A new instance of AbstractFormBuilder.
-
#label(field, options = {}) ⇒ Object
f.label :username, :caption => “Nickname”.
-
#password_field(field, options = {}) ⇒ Object
f.password_field :password, :id => ‘password’.
-
#radio_button(field, options = {}) ⇒ Object
f.radio_button :gender, :value => ‘male’.
-
#select(field, options = {}) ⇒ Object
f.select :color, :options => [‘red’, ‘green’], :include_blank => true f.select :color, :collection => @colors, :fields => [:name, :id].
-
#submit(caption = "Submit", options = {}) ⇒ Object
f.submit “Update”, :class => ‘large’.
-
#text_area(field, options = {}) ⇒ Object
f.text_area :summary, :value => “(enter summary)”, :id => ‘summary’.
-
#text_field(field, options = {}) ⇒ Object
f.text_field :username, :value => “(blank)”, :id => ‘username’.
Constructor Details
#initialize(view_context, object) ⇒ AbstractFormBuilder
Returns a new instance of AbstractFormBuilder.
7 8 9 10 11 12 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 7 def initialize(view_context, object) @view_context = view_context @object = object raise "FormBuilder view_context must be initialized!" unless view_context raise "FormBuilder object must be not be nil value. If there's no object, use a symbol instead! (i.e :user)" unless object end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
5 6 7 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 5 def object @object end |
#view_context ⇒ Object
Returns the value of attribute view_context.
5 6 7 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 5 def view_context @view_context end |
Instance Method Details
#check_box(field, options = {}) ⇒ Object
f.check_box :remember_me, :value => ‘true’, :uncheck_value => ‘0’
57 58 59 60 61 62 63 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 57 def check_box(field, ={}) unchecked_value = .delete(:uncheck_value) || '0' .reverse_merge!(:id => field_id(field), :value => '1') .merge!(:checked => true) if values_matches_field?(field, [:value]) html = @view_context.check_box_tag field_name(field), html << hidden_field(field, :value => unchecked_value, :id => nil) end |
#error_messages(options = {}) ⇒ Object
f.error_messages
15 16 17 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 15 def (={}) @view_context.(@object, ) end |
#file_field(field, options = {}) ⇒ Object
f.file_field :photo, :class => ‘avatar’
73 74 75 76 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 73 def file_field(field, ={}) .reverse_merge!(:id => field_id(field)) @view_context.file_field_tag field_name(field), end |
#hidden_field(field, options = {}) ⇒ Object
f.hidden_field :session_id, :value => “45”
26 27 28 29 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 26 def hidden_field(field, ={}) .reverse_merge!(:value => field_value(field), :id => field_id(field)) @view_context.hidden_field_tag field_name(field), end |
#image_submit(source, options = {}) ⇒ Object
f.simage_submitubmit “buttons/submit.png”, :class => ‘large’
84 85 86 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 84 def image_submit(source, ={}) @view_context.image_submit_tag source, end |
#label(field, options = {}) ⇒ Object
f.label :username, :caption => “Nickname”
20 21 22 23 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 20 def label(field, ={}) .reverse_merge!(:caption => field.to_s.titleize) @view_context.label_tag(field_id(field), ) end |
#password_field(field, options = {}) ⇒ Object
f.password_field :password, :id => ‘password’
44 45 46 47 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 44 def password_field(field, ={}) .reverse_merge!(:value => field_value(field), :id => field_id(field)) @view_context.password_field_tag field_name(field), end |
#radio_button(field, options = {}) ⇒ Object
f.radio_button :gender, :value => ‘male’
66 67 68 69 70 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 66 def (field, ={}) .reverse_merge!(:id => field_id(field, [:value])) .merge!(:checked => true) if values_matches_field?(field, [:value]) @view_context. field_name(field), end |
#select(field, options = {}) ⇒ Object
f.select :color, :options => [‘red’, ‘green’], :include_blank => true f.select :color, :collection => @colors, :fields => [:name, :id]
51 52 53 54 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 51 def select(field, ={}) .reverse_merge!(:id => field_id(field), :selected => field_value(field)) @view_context.select_tag field_name(field), end |
#submit(caption = "Submit", options = {}) ⇒ Object
f.submit “Update”, :class => ‘large’
79 80 81 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 79 def submit(="Submit", ={}) @view_context.submit_tag , end |
#text_area(field, options = {}) ⇒ Object
f.text_area :summary, :value => “(enter summary)”, :id => ‘summary’
38 39 40 41 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 38 def text_area(field, ={}) .reverse_merge!(:value => field_value(field), :id => field_id(field)) @view_context.text_area_tag field_name(field), end |
#text_field(field, options = {}) ⇒ Object
f.text_field :username, :value => “(blank)”, :id => ‘username’
32 33 34 35 |
# File 'lib/any_view/form_builder/abstract_form_builder.rb', line 32 def text_field(field, ={}) .reverse_merge!(:value => field_value(field), :id => field_id(field)) @view_context.text_field_tag field_name(field), end |