I do not have the privilege to comment on the answers to other questions, but I have a question related to him to Nerian, so we will publish this. I use code like
before_create : create_rest def create_rest 15.times do self.players.build({:name => Rnlist.order("rand()").first.raname, :cost => 140+rand(40), :coop => rand(3)}) end end
in the user.rb model. This code works fine and creates 15 players with different names, etc. However, if I try to put attributes in the player model as you suggest (using the create method in the players_controller controller), the self.players.build method creates 15 players with empty attributes without any errors. I thought trying to use code with a new method instead of creating in player_controller might solve this, but the result is the same. Can self.players.build method cause a problem? I checked the Ruby API for others.build (), as well as the Vinhboy.com blog , but could not solve this problem.
source share