Method: ActiveRecord::Core#init_with

Defined in:
lib/active_record/core.rb

#init_with(coder) ⇒ Object

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'


214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/active_record/core.rb', line 214

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