# Can create record but can not update it =\> has\_many through

**URL:** <https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811>\
**Category:** Rails\
**Created:** [June 7, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811 "2008-06-07T12:13:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [June 7, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811/1 "2008-06-07T12:13:23Z")

</div>

Hi All,

I have a problem using has\_many through association. I can create a  
product  
without problem, but when i edit it, i got this NoMethodError:

undefined method `reciters=’ for #Product:0xb71a77e8

Did i miss something to code? I provided the codes below. Please help

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 …

---

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [June 7, 2008, 12:23pm UTC](https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811/2 "2008-06-07T12:23:28Z")

</div>

On Jun 7, 11:12 am, “Adinda P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi All,
> 
> I have a problem using has\_many through association. I can create a product  
> without problem, but when i edit it, i got this NoMethodError:
> 
> undefined method `reciters=’ for #Product:0xb71a77e8
> 
> Did i miss something to code? I provided the codes below. Please help

has\_many :through doesn’t have foos= before rails 2.1

Fred

---

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [June 8, 2008, 9:57am UTC](https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811/3 "2008-06-08T09:57:23Z")

</div>

On Sat, Jun 7, 2008 at 6:22 PM, Frederick C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> has\_many :through doesn’t have foos= before rails 2.1

Would you explain your answer a bit more? How come i can create a record  
without the error as i got when i was trying to update it? Any  
reference?  
Other solution to use instead?

Thanks,

Adinda P

---

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [June 8, 2008, 12:42pm UTC](https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811/4 "2008-06-08T12:42:06Z")

</div>

On Jun 8, 8:56 am, “Adinda P.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

Pretty much what I said. if you have has\_many :customers you can do  
customers= …, but if you have has\_many :customers, :through  
=\> :something\_else, then until 2.1 you can’t do it. It’s just not  
implemented (you’ll have to do it yourself using the methods that are  
available - the documentation on associations has a table of which  
association types have which methods).

Fred

---

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [June 8, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811/5 "2008-06-08T17:26:19Z")

</div>

On Sun, Jun 8, 2008 at 6:41 PM, Frederick C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Pretty much what I said. if you have has\_many :customers you can do  
> customers= …, but if you have has\_many :customers, :through  
> =\> :something\_else, then until 2.1 you can’t do it. It’s just not  
> implemented (you’ll have to do it yourself using the methods that are  
> available - the documentation on associations has a table of which  
> association types have which methods).

I tried with @product.reciter\_ids = params[:reciters] before and i also  
got  
NoMethodError. Please help.

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

Thanks,

Adinda P

Fred

---

<div class="post-metadata">

**Author:** ![adinda\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@adinda\_p](https://www.ruby-forum.com/u/adinda_p)\
**Post date:** [June 8, 2008, 6:19pm UTC](https://www.ruby-forum.com/t/can-create-record-but-can-not-update-it-has-many-through/139811/6 "2008-06-08T18:19:58Z")

</div>

On 8 Jun 2008, at 16:25, Adinda P. wrote:

> I tried with @product.reciter\_ids = params[:reciters] before and i  
> also got NoMethodError. Please help.

foo\_ids= doesn’t exist either. You need to use \<\<, delete etc… (or  
upgrade to 2.1)

Fred
