0

このように定義された3つのクラスPicture、Employee、およびProductがあります

Class Picture < ActiveRecord::Base
  belongs_to :imageable, :polymorphic => true
end

class Employee < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end

class Product < ActiveRecord::Base
  has_many :pictures, :as => :imageable
end

画像のモデル名を画像に変更したいです。ポリモーフィック アソシエーションに関して、何を更新する必要がありますか?

4

1 に答える 1

2

picture.rbまず、ファイル名を からにimage.rb、クラス名を からPictureImage、関連付けを からhas_many :picturesにリネームしますhas_many :images

次に、pictures テーブルを変更する移行を次のように作成します。

class RenamePicturesToImages < ActiveRecord::Migration
  def change
    rename_table :pictures, :images
  end
end

最後に実行しrake db:migrateます。

于 2012-10-11T16:54:29.553 に答える