Class: Erector::FormFor::Form
- Inherits:
-
InlineWidget
- Object
- InlineWidget
- Erector::FormFor::Form
- Defined in:
- lib/erector/form_for.rb
Instance Attribute Summary collapse
-
#object_name ⇒ Object
readonly
Returns the value of attribute object_name.
Instance Method Summary collapse
- #fields(attrs = {}, &block) ⇒ Object
- #form_input(field, attrs = {}) ⇒ Object
-
#initialize(app, object, opts, &block) ⇒ Form
constructor
A new instance of Form.
Constructor Details
#initialize(app, object, opts, &block) ⇒ Form
Returns a new instance of Form.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/erector/form_for.rb', line 15 def initialize app, object, opts, &block assigns = {} @app = app @object = object @opts = opts @object_name = opts.delete(:object_name) assigns[:method] = opts.delete(:method) if opts.has_key?(:action) assigns[:action] = opts.delete(:action) end if object_is_record? @object_name ||= object.class.table_name.to_s.singularize if object.new_record? assigns[:action] ||= app.path_for("new_#{object_name}") if app.respond_to?(:path_for) assigns[:method] ||= 'post' opts[:id] ||= "new-#{object_name}" else assigns[:action] ||= app.path_for("edit_#{object_name}", object) if app.respond_to?(:path_for) assigns[:method] ||= 'put' opts[:id] ||= "edit-#{object_name}" end end super assigns, &block @method = @method.to_s @action = @app.url @action end |
Instance Attribute Details
#object_name ⇒ Object (readonly)
Returns the value of attribute object_name.
12 13 14 |
# File 'lib/erector/form_for.rb', line 12 def object_name @object_name end |
Instance Method Details
#fields(attrs = {}, &block) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/erector/form_for.rb', line 46 def fields attrs = {}, &block legend_text = attrs.delete(:legend) fieldset attrs do ol &block legend(legend_text) if legend_text end end |
#form_input(field, attrs = {}) ⇒ Object
54 55 56 |
# File 'lib/erector/form_for.rb', line 54 def form_input field, attrs = {} WrappedInput.new(@app, @object, @object_name, field, attrs) end |