My controller rm_grants_controller.rb snip:
class RmGrantsController < ApplicationController
def dump
File.open(‘db/backup/rm_grants.yaml’, ‘w’) { |f| f.puts
RmGrants.find(:all).to_yaml }
end
end
This creates ‘db/backup/rm_grants.yaml’ whose content look like
-
!ruby/object:RmGrant
attributes:
key1: value1
key2: value2
key3: value3
attributes_cache: {} -
!ruby/object:RmGrant
attributes:
key1: value1
key2: value2
key3: value3
attributes_cache: {}
Now, I want to reconstruct ActiveRecord from the yaml file, so in
rm_grants_controllers.rb
def load
records = YAML.load_file(‘db/backup/rm_grants.yml’)
records.each do |record|
@rm_grant = RmGrant.new(params[record])
@rm_grants.save!
end
end
But that doesn’t do what I hope, which is to re-create all the
records. All it does is create empty records.
puts record.inspect shows
#<YAML::Object:0x5d26950 @class=“RmGrant”, @ivars={“attributes_class”-
{}, “attributes”=>{“key1”=>“value1”, “key2”=>“value2”,
“key3”=>“value3”}}>
But I have no idea what this means nor how to decipher it.