YML to ActiveRecord

Hello I'm trying to load a yaml to a activerecord object.
The method 'salvar_datos' save the data to a yaml file.
The method 'cargar_datos' load the data from a yaml file.

When I call 'salvar_datos' all go fine, but when I run 'cargar_datos'
exception is throw

`attribute_names': undefined method `keys' for nil:NilClass
(NoMethodError) ......

The problem is around 'roles = YAML.load(archivo)'

require 'rubygems'
require 'active_record'

class Rol < ActiveRecord::Base

  ActiveRecord::Base.establish_connection( :adapter =>
'postgresql', :host => 'localhost', :username => 'postgres', :database
=> 'mi_bd', :port => '5432');

  def salvar_datos

    roles = Rol.all

    archivo = File.open('/home/aconsuegra/Escritorio/salida.yml','w')


  def cargar_datos

    archivo = File.open('/home/aconsuegra/Escritorio/salida.yml')
    roles = YAML.load(archivo)

    roles.each do |un_rol|



#puts roles