私はそのようなコードを持っています:
def update
@oil = Oil.find(params[:id])
@product_types = ProductType.all
if @oil.update_attributes(params[:oil])
if @oil.other_products_cross_lists.update_attributes(:cross_value => @oil.model.to_s.gsub(/\s+/, "").upcase)
redirect_to admin_oils_path
end
else
render :layout => 'admin'
end
end
しかし、私がそれを実行すると、次のようになります:
undefined method `update_attributes' for #<ActiveRecord::Relation:0x007f7fb4cdc220>
私のother_products_cross_listsは更新されていません...また、update_attributeを試しても同じエラーが発生します。
私は何を間違っていますか?
また、destroy メソッドを実行すると
def destroy
@oil = Oil.find(params[:id])
if @oil.destroy
if @oil.other_products_cross_lists.destroy
redirect_to admin_oils_path
end
else
render :layout => 'admin'
end
end
other_products_cross_lists は破棄されませんでした...
どうすればこの問題を解決できますか?
モデル:
class Oil < ActiveRecord::Base
has_many :other_products_cross_lists, :foreign_key => 'main_id'
class OtherProductsCrossList < ActiveRecord::Base
belongs_to :oil