How to change all values for object

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?

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

From the docs...

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

Regards,
Jordan

···

On Nov 27, 5:48 am, Bober <sebastian.bobrow...@gmail.com> wrote:

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?

Look at the ruby documentation for the Hash class...

http://www.ruby-doc.org/core/classes/Hash.html

Thank you