2

我有以下型号:

class User < ActiveRecord::Base
  has_one :image_assignment, as: :imageable
  has_one :image, through: :image_assignment
end

class ImageAssignment < ActiveRecord::Base
  belongs_to :image
  belongs_to :imageable, polymorphic: true
end

class Image < ActiveRecord::Base
  mount_uploader :image, ImageUploader
end

u = User.new
u.create_image #=> undefined method `create_image'
4

1 回答 1

2

这是正确的。您需要先构建/创建 image_assignment

u.create_image_assignment
u.image_assignment.create_image
于 2012-05-14T19:40:12.387 回答