【发布时间】:2014-12-02 01:25:47
【问题描述】:
我在 Rails 中遇到了多态问题。
我有这些文件:
class CreateExecutions < ActiveRecord::Migration
def change
create_table :executions do |t|
t.integer :player_space_id
t.integer :what_id
t.references :what, polymorphic: true
t.integer :qty
t.integer :level
t.datetime :when_ready
t.timestamps
end
end
end
class Execution < ActiveRecord::Base
belongs_to :what, :polymorphic => true
end
class Element < ActiveRecord::Base
belongs_to :game_space
has_many :levels
has_many :player_elements
has_many :executions, :as => what
end
class PlayerSpace < ActiveRecord::Base
belongs_to :game_space
belongs_to :user
has_many :executions, as: :what
end
当我运行具有 Element 的控制器时,出现此错误:
PlayerSpacesController#show 中的名称错误 # 未定义的局部变量或方法“what”
你能帮帮我吗
【问题讨论】:
标签: ruby-on-rails polymorphism