method

init_with

rails latest stable - Class: ActiveRecord::Core::ClassMethods

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v7.0.0) is shown here.

init_with(coder, &block)
public

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'