2
我有一个多态关联对我的用户模型轨态关联参考
class User < ActiveRecord::Base
has_many :attachments, as: :attachable
的如下
class Attachment < ActiveRecord::Base
belongs_to :attachable, polymorphic: true
has_attached_file :file
end
然后,我希望能够做到以下几点
attachment = Attachment.create(:file => params[:attachment])
attachment.user = current_user
但我得到一个
*** NoMethodError Exception: undefined method `user=' for #<Attachment:0x007fee92901ce8>
有什么确切的错误信息?你给的那个不够具体。 –
*** NoMethodError例外:未定义的方法'用户=”为#<附件:0x007fee92901ce8> – Petran
多态关联可以被反转 –