STI with Ploymorphic association in rails -


i have model named slider

class slider < activerecord::base  end 

and homebannerslider has single table inheritance relation slider

class homebannerslider < slider      has_many :images, as: :imageable     accepts_nested_attributes_for :images, reject_if: :all_blank, allow_destroy: true  end 

and image model given

class image < activerecord::base    belongs_to :imageable, polymorphic: true    has_attached_file :image end 

my problem whenever save homebannerslider following command

      @admin_home_banner_slider = homebannerslider.new(admin_home_banner_slider_params)       @admin_home_banner_slider.save 

it saves imageable_type in image model slider

@admin_home_banner_slider.images <image:0x007f5e6ef7af20   id: nil,   imageable_id: nil,   imageable_type: "slider",   title: "2",   description: "2",   link_button: nil,   link_button_title: nil,   owner: nil,   publish: nil,   priority: nil,   created_at: nil,   updated_at: nil,   image_file_name: nil,   image_content_type: nil,   image_file_size: nil,   image_updated_at: nil>] 

but want store imageable_type homebannerslider

try add in image model:

before_validation :set_type  def set_type   self.imageable_type = imageable.class.name end 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -