undefined method '<<' for polymorphic association

369 views
Skip to first unread message

fugee ohu

unread,
Sep 10, 2019, 12:02:36 AM9/10/19
to Ruby on Rails: Talk
class Item < ApplicationRecord
 has_many :pictures, as: :imageable
end

class Picture < ApplicationRecord
 belongs_to :imageable, polymorphic: true, optional: true
end

NoMethodError in PicturesController#create

undefined method `<<' for #<Picture:0x007f3758cc88f0>


@item.pictures.create << @picture

Ariel Juodziukynas

unread,
Sep 10, 2019, 12:33:41 AM9/10/19
to rubyonra...@googlegroups.com
You can do @item.pictures << @picture

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ad30bf7-4b54-49e7-86ab-8544049e567c%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages