Class: Paramount::Model
- Inherits:
-
Object
- Object
- Paramount::Model
- Includes:
- ActiveModel::Model
- Defined in:
- lib/paramount/model.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
Class Method Summary collapse
-
.find(id) ⇒ Object
This ‘factory’ meant for show/edit takes no params and uses the model attributes to seed the virtus attributes usage in controller : BookParam.find(params).
-
.model_class ⇒ Object
def self.model_name raise “self.model_name needs to be defined” end.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(params = nil, model = nil) ⇒ Model
constructor
A new instance of Model.
- #persisted? ⇒ Boolean
- #save ⇒ Object (also: #update)
- #submit ⇒ Object
Constructor Details
#initialize(params = nil, model = nil) ⇒ Model
Returns a new instance of Model.
24 25 26 27 28 |
# File 'lib/paramount/model.rb', line 24 def initialize(params = nil, model = nil) @model= model params ||= model.attributes super(params) end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
6 7 8 |
# File 'lib/paramount/model.rb', line 6 def model @model end |
Class Method Details
.find(id) ⇒ Object
This ‘factory’ meant for show/edit takes no params and uses the model attributes to seed the virtus attributes usage in controller : BookParam.find(params)
19 20 21 22 |
# File 'lib/paramount/model.rb', line 19 def self.find(id) model = model_class.find(id) new(model.attributes, model) end |
.model_class ⇒ Object
def self.model_name
raise "self.model_name needs to be defined"
end
12 13 14 |
# File 'lib/paramount/model.rb', line 12 def self.model_class @klass ||= model_name.name.constantize end |
Instance Method Details
#id ⇒ Object
30 31 32 |
# File 'lib/paramount/model.rb', line 30 def id model.id end |
#persisted? ⇒ Boolean
44 45 46 |
# File 'lib/paramount/model.rb', line 44 def persisted? model.new_record? ? false : true end |
#save ⇒ Object Also known as: update
34 35 36 37 |
# File 'lib/paramount/model.rb', line 34 def save assign model.save end |
#submit ⇒ Object
40 41 42 |
# File 'lib/paramount/model.rb', line 40 def submit valid? ? persist! : false end |