el tipo de imagen no se configura para asociaciones polimórficas
Tengo dos modelos en mi aplicación rails 4.2
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
y
class Image < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
end
Tengo un problema con imageable_type que no se configura en consecuencia, por ejemplo, si hago esto en la consola
landingpage = LandingPage.first
image = landingpage.build_section2_photo
pero cuando lo hago
image.imageable_type
yo obtengo
"LandingPage"
más bien que
"Section2Photo"