0

我目前正在使用 Mongoid 进行 Rails 项目。我Game定义了一个模型,其中嵌入了许多GamePlayers. 不幸的是,我不知道如何创建新游戏。我可以使用 来创建没有玩家的游戏Game.create,但是当我也尝试为游戏创建玩家时,它会出现语法错误。我已经尝试在线搜索,但我无法找到任何与问题相关的内容。

这是我在GamesController.

  def new
    @game = Game.create(
        epoch: 1,    
        turn: 0,
        auction_turn: -1,
        auction_type: -1,
        sun: 1,
        ras: 0,
        auction_track: []

        game_players: [ #doesn't work
          { suns:[9,6,5,2]
          }        
        ]      
    )

    redirect_to :action => "show", :id => @game._id
  end

产生错误

/home/<redacted>/Ra/ra_server/app/controllers/games_controller.rb:36: syntax error, unexpected tIDENTIFIER, expecting ')'
        game_players: [ #doesn't work

这是我的模型

class Game
  include Mongoid::Document

  field :epoch, type:Integer
  field :turn, type:Integer
  field :auction_turn, type:Integer
  field :auction_type, type:Integer
  field :sun, type:Integer
  field :ras, type:Integer
  field :auction_track, type:Array


  embeds_many :game_players 
end

class GamePlayer
  include Mongoid::Document

  field :score, type:Integer
  field :bid, type:Integer
  field :suns, type:Array
  field :next_suns, type:Array
  field :pharaohs, type:Integer
  field :niles, type:Integer
  field :floods, type:Integer
  field :gods, type:Integer
  field :gold, type:Integer
  field :civilizations, type:Array
  field :monuments, type:Array

  embedded_in :game
end
4

1 回答 1

1

您的参数中的auction_track: [] 之后似乎缺少逗号。

于 2013-04-10T21:56:05.087 回答