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
多態關聯可以被反轉 –