undefined method '<<' for polymorphic association

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

undefined method '<<' for polymorphic association

fugee ohu
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ad30bf7-4b54-49e7-86ab-8544049e567c%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: undefined method '<<' for polymorphic association

Ariel Juodziukynas
You can do @item.pictures << @picture

El mar., 10 sep. 2019 01:02, fugee ohu <[hidden email]> escribió:
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1ad30bf7-4b54-49e7-86ab-8544049e567c%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcBtHJWywOUZ80EVUPqa5WeQ69o6FOZ7hfQ3KrT9V_c5qQ%40mail.gmail.com.