instance method
init_with
Ruby on Rails 4.1.16
Since v4.0.13Signature
init_with(coder)
Initialize an empty model object from coder. coder must contain the attributes necessary for initializing an empty model object. For example:
class Post < ActiveRecord::Base end post = Post.allocate post.init_with('attributes' => { 'title' => 'hello world' }) post.title # => 'hello world'
Parameters
-
coderreq
Source
# File activerecord/lib/active_record/core.rb, line 211
def init_with(coder)
@attributes = self.class.initialize_attributes(coder['attributes'])
@column_types_override = coder['column_types']
@column_types = self.class.column_types
init_internals
@new_record = false
self.class.define_attribute_methods
run_callbacks :find
run_callbacks :initialize
self
end
Defined in activerecord/lib/active_record/core.rb line 211
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Core