Hai all,

Saya masih kurang pd untuk coding model yang punya asosiasi has_many
through. Saya berhasil buat Product sesuai dengan asosiasi yang diharapkan,
tapi nggak bisa update dengan error NoMethodError:

undefined method `reciters=' for #<Product:0xb71a77e8>


Padahal di procuct_controller sama2 pake @product.reciters. Tapi kenapa pas
update nggak bisa ya..? Please help. Di bawah saya sisipkan potongan kode2
terkait.

Thanks,

Dida


product_controller.rb
======================
def create
    @product = Product.new(params[:product])

    if @product.save
      unless params[:reciters].blank?
        @product.reciters << Qori.find(params[:reciters])
      end
      flash[:notice] = 'New product successfully created.'
      redirect_to :action => 'index'
    else
      render :action => 'new'
    end
end

def update
    @product = Product.find(params[:id])

    @product.update_attributes(params[:product])

    unless params[:reciters].blank?
      @product.reciters = Qori.find(params[:reciters])
    end

    if @product.save
      flash[:notice] = 'Product has been updated.'
      redirect_to :action => 'show', :id => @product
    else
      render :action => 'edit'
    end
end

================== product_controller.rb

product.rb
==================
class Product < ActiveRecord::Base
  ...
  has_many    :pilihan_qoris
  has_many    :reciters, :through => :pilihan_qoris, :source => :qori
  ...

qori.rb
=================
class Qori < ActiveRecord::Base
  has_many :products
  has_many :pilihan_qoris
  has_many :creations, :through => :pilihan_qoris, :source => :product
  ...
=================


[Non-text portions of this message have been removed]

Kirim email ke