Class: Form
- Inherits:
-
Object
- Object
- Form
- Defined in:
- lib/keight/skeleton/app/model.rb
Overview
Form class
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Class Method Summary collapse
Instance Method Summary collapse
- #error(name) ⇒ Object
-
#initialize(params = {}) ⇒ Form
constructor
A new instance of Form.
- #populate_into(model) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Form
Returns a new instance of Form.
50 51 52 |
# File 'lib/keight/skeleton/app/model.rb', line 50 def initialize(params={}) @params = params end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
54 55 56 |
# File 'lib/keight/skeleton/app/model.rb', line 54 def errors @errors end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
54 55 56 |
# File 'lib/keight/skeleton/app/model.rb', line 54 def params @params end |
Class Method Details
.new_from(model) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/keight/skeleton/app/model.rb', line 56 def self.new_from(model) params = { #'val' => model.val, } self.new(params) end |
Instance Method Details
#error(name) ⇒ Object
78 79 80 |
# File 'lib/keight/skeleton/app/model.rb', line 78 def error(name) @errors[name] end |
#populate_into(model) ⇒ Object
82 83 84 85 |
# File 'lib/keight/skeleton/app/model.rb', line 82 def populate_into(model) #model.val = @params['val'].to_i return model end |
#validate ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/keight/skeleton/app/model.rb', line 63 def validate @errors = errors = {} # #k = 'val' #v = @params[k].to_s.strip #if v.empty? # errors[k] = "Required" #elsif v !~ /\A\d+\z/ # errors[k] = "Integer expected" #end #@params[k] = v # return errors end |