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"
activerecord postgresql ruby-on-rails-4
Asnad Atta Dec 17 '15 at 7:16 2015-12-17 07:16
source share