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''
a
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
end
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'')
YAML.dump(roles,archivo)
archivo.close
end
def cargar_datos
archivo =
File.open(''/home/aconsuegra/Escritorio/salida.yml'')
roles = YAML.load(archivo)
archivo.close
roles.each do |un_rol|
un_rol.save
end
end
#puts roles
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.