instance method
init_with
Ruby on Rails 7.1.6
Since v4.0.13Signature
init_with(coder, &block)
Initialize an empty model object from coder. coder should be the result of previously encoding an Active Record model, using #encode_with.
class Post < ActiveRecord::Base end old_post = Post.new(title: "hello world") coder = {} old_post.encode_with(coder) post = Post.allocate post.init_with(coder) post.title # => 'hello world'
Parameters
-
coderreq -
blockblock
Source
# File activerecord/lib/active_record/core.rb, line 473
def init_with(coder, &block)
coder = LegacyYamlAdapter.convert(coder)
attributes = self.class.yaml_encoder.decode(coder)
init_with_attributes(attributes, coder["new_record"], &block)
end
Defined in activerecord/lib/active_record/core.rb line 473
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Core