# How to change all values for object

**URL:** <https://www.ruby-forum.com/t/how-to-change-all-values-for-object/121376>\
**Category:** Ruby\
**Created:** [November 27, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/how-to-change-all-values-for-object/121376 "2007-11-27T12:51:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bober](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b5e925/32.png) [@Bober](https://www.ruby-forum.com/u/Bober)\
**Post date:** [November 27, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/how-to-change-all-values-for-object/121376/1 "2007-11-27T12:51:19Z")

</div>

Hello!  
I need change all values of Active Record Object

// Post - obiekt AR

@invo = Post.find(params[:id])  
@a = @invo.attributes

@a.each { |m, n|  
@invo.m = “new\_value”  
}

But, I see "undefined method `m=’ "

what is wrong?  
how can I change values?

---

<div class="post-metadata">

**Author:** ![Bober](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b5e925/32.png) [@Bober](https://www.ruby-forum.com/u/Bober)\
**Post date:** [November 27, 2007, 1:06pm UTC](https://www.ruby-forum.com/t/how-to-change-all-values-for-object/121376/2 "2007-11-27T13:06:40Z")

</div>

Bober wrote:

> @invo = Post.find(params[:id])  
> @a = @invo.attributes
> 
> @a.each { |m, n|  
> @invo.m = “new\_value”  
> }
> 
> But, I see "undefined method `m=’ "

Because you are calling the literal method “m=”, which doesn’t exist.  
You want instead, something like (untested, I don’t use ActiveRecord).

@invo.send("#{m}=", “new\_value”)

alex

---

<div class="post-metadata">

**Author:** ![Bober](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b5e925/32.png) [@Bober](https://www.ruby-forum.com/u/Bober)\
**Post date:** [November 27, 2007, 2:56pm UTC](https://www.ruby-forum.com/t/how-to-change-all-values-for-object/121376/3 "2007-11-27T14:56:05Z")

</div>

On Nov 27, 5:48 am, Bober [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> }
> 
> But, I see "undefined method `m=’ "
> 
> what is wrong?  
> how can I change values?

From the docs…

[http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001069](http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001069)

…it appears that @a would be a Hash. If that is correct, you have to  
use the subscript operator (or #store) to change the items…

@invo = Post.find(params[:id])  
@a = @invo.attributes

@a.each { |m, n|  
@invo[m] = “new\_value”

# ^^^

}

Look at the ruby documentation for the Hash class…

[http://www.ruby-doc.org/core/classes/Hash.html](http://www.ruby-doc.org/core/classes/Hash.html)

Regards,  
Jordan

---

<div class="post-metadata">

**Author:** ![Bober](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/b5e925/32.png) [@Bober](https://www.ruby-forum.com/u/Bober)\
**Post date:** [November 27, 2007, 7:20pm UTC](https://www.ruby-forum.com/t/how-to-change-all-values-for-object/121376/4 "2007-11-27T19:20:50Z")

</div>

> Look at the ruby documentation for the Hash class…
> 
> [class Hash - RDoc Documentation](http://www.ruby-doc.org/core/classes/Hash.html)

Thank you
