Rails多态图像与载波

时间:2014-01-10 13:40:35

标签: ruby-on-rails ruby-on-rails-3 carrierwave polymorphic-associations

嗨,大家好我有问题在Rail 3.2中制作图像模型多态。我有多态图像模型:

#schema: imageable_id:integer, imageable_type:string image:string,application_id:integer
class Image < ActiveRecord::Base
  attr_accessible :image, :application_id
  validates :image, presence: true
  belongs_to :imageable, polymorphic: true
  belongs_to :application
  mount_uploader :image, ImagesUploader
end

我希望首先使用关卡模型加入此图像模型:

class Level < ActiveRecord::Base
  #schema application_id:integer, :image:string
  attr_accessible :image
  accepts_nested_attributes_for :image
  has_one :image, as: :imageable
  belongs_to :application
end

所以当我现在去rails console并尝试获取任何级别时,我有以下错误:

Level.last
ArgumentError: No association found for name `image'. Has it been defined yet?

怎么了?可以解释一下吗? 提前谢谢

0 个答案:

没有答案