From: "Eduardo Yáñez Parareda" Date: 2006-07-19T19:35:11+09:00 Subject: Re: Rails: Saving an object into DB After some changes, same error. I don't understand anything, I have a model class Player, a table players and the only thing I want to do is create a new player and save it in the database. I have another models and when I save them through a view generated by Rails it works fine. /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1557:in `attribute_names' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:2060:in `clone_attributes' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1519:in `attributes' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1945:in `attributes_with_quotes' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1725:in `update_without_lock' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/locking.rb:33:in `update_without_callbacks' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/callbacks.rb:274:in `update_without_timestamps' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/timestamp.rb:39:in `update' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1718:in `create_or_update_without_callbacks' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/callbacks.rb:249:in `create_or_update' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/base.rb:1392:in `save_without_validation' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/validations.rb:724:in `save_without_transactions' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactions.rb:126:in `save' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in `transaction' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactions.rb:91:in `transaction' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactions.rb:118:in `transaction' /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.3/lib/active_record/transactions.rb:126:in `save' #{RAILS_ROOT}/app/models/player.rb:21:in `create_player' app/controllers/team_controller.rb:53:in `add_player' I've added some accessors because I don't know if they are needed by ActiveRecord, but nothing changes. class Player < ActiveRecord::Base attr_reader :team_id, :name, :age, :goal, :defence, :stamina, :goalkeeper, :playmaking, :pass, :shot, :speed, :head, :creativity, :free_kicks, :captain, :mood, :aggresiveness attr_writer :team_id, :name, :age, :goal, :defence, :stamina, :goalkeeper, :playmaking, :pass, :shot, :speed, :head, :creativity, :free_kicks, :captain, :mood, :aggresiveness belongs_to :team def initialize # De momento ponemos cualquier cosa, un numero aleatorio como cadena @name = (rand * 1000000).truncate.to_s # Edad entre 20 y 34 años @age = rand(34) + 1 + 20 end # Crea un jugador con los valores por defecto def Player.create_player(team_id) player = Player.new player.team_id = team_id player.save end # Relaciona el jugador con un equipo def relate_to_team(team_id) @team_id = team_id end end