Class: Formic::Form
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Attributes inherited from Base
#content, #options, #page, #template
Instance Method Summary collapse
- #_initialize(options = {}, &block) ⇒ Object
- #_initialize_with_model(model, action, classname, options = {}, &block) ⇒ Object
- #create(model, options = {}, &block) ⇒ Object
- #edit(model, options = {}, &block) ⇒ Object
- #method_missing(action, model, options = {}, &block) ⇒ Object
- #put(options = {}, &block) ⇒ Object
Methods inherited from Base
#add_class, default_template, #formics, #has_class?, #initialize, #merge_options, template, #to_s
Constructor Details
This class inherits a constructor from Formic::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(action, model, options = {}, &block) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/formic/form.rb', line 46 def method_missing action, model, ={}, &block @action = action [:title] ||= "#{action} #{model.class.to_s.underscore}".gsub('_', ' ').titleize return _initialize_with_model( model, [:action] || "#{self.page.url_for(model)}/#{action}", "#{action}_#{model.class.to_s.downcase}_form", , &block ) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/formic/form.rb', line 5 def action @action end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/formic/form.rb', line 5 def model @model end |
Instance Method Details
#_initialize(options = {}, &block) ⇒ Object
7 8 9 10 |
# File 'lib/formic/form.rb', line 7 def _initialize ={}, &block super , &block self.[:method] ||= 'POST' end |
#_initialize_with_model(model, action, classname, options = {}, &block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/formic/form.rb', line 58 def _initialize_with_model model, action, classname, ={}, &block [:title] ||= "#{action} #{model.class.to_s.underscore}".gsub('_', ' ').titleize @model = model self.() self.[:method] ||= 'POST' self.[:action] ||= action self.[:class].push classname self.content = block if block_given? return self end |
#create(model, options = {}, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/formic/form.rb', line 19 def create model, ={}, &block [:title] ||= "New #{model.class.to_s.underscore}".gsub('_', ' ').titleize @action = :create return _initialize_with_model( model, [:action] || self.page.url_for(model), "create_#{model.class.to_s.downcase}_form", , &block ) end |
#edit(model, options = {}, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/formic/form.rb', line 32 def edit model, ={}, &block self.put @action = :edit [:title] ||= "Edit #{model.class.to_s.underscore}".gsub('_', ' ').titleize return _initialize_with_model( model, [:action] || self.page.url_for(model), "edit_#{model.class.to_s.downcase}_form", , &block ) end |
#put(options = {}, &block) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/formic/form.rb', line 12 def put ={}, &block self.[:method ] = 'POST' self.[:_method] = 'PUT' self.content = block if block_given? return self end |