The figurative type is not set for polymorphic associations

I have two models in my rails 4.2 application

class LandingPage < ActiveRecord::Base has_one :section2_photo, -> { where imageable_type: "Section2Photo"}, class_name: Image, foreign_key: :imageable_id, foreign_type: :imageable_type, dependent: :destroy, as: :imageable has_one :section3_photo, -> { where imageable_type: "Section3Photo"}, class_name: Image, foreign_key: :imageable_id, foreign_type: :imageable_type, dependent: :destroy, as: :imageable end 

and

 class Image < ActiveRecord::Base belongs_to :imageable, polymorphic: true end 

I have a problem with imageable_type that does not set accordingly, for example if I do it in the console

 landingpage = LandingPage.first image = landingpage.build_section2_photo 

but when i do

 image.imageable_type 

I get

 "LandingPage" 

but not

 "Section2Photo" 
+1
activerecord postgresql ruby-on-rails-4
Dec 17 '15 at 7:16
source share
1 answer

just posting to others that I deleted

 as: :imageable 

and now works great

+1
Dec 17 '15 at 7:44
source share



All Articles