Bober
1
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
2
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
Bober
3
On Nov 27, 5:48 am, Bober [email protected] 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
…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