Should be simple but I can’t eval a string as a method call. I have
poked around online a fair amount to get to the bottom of this mundane
task, with no results.
I have a hash “fields” that contains a series of AR field names and an
object called “news” which is an AR object with that has the field
names that are coming in from the hash. I just want to assign the hash
values to the same field value from the news object.
I have tried all these variations but with no luck. Mostly just blows
up with syntax errors.
fields.each_pair {|key, value| news.eval(“key”) = value }
fields.each_pair {|key, value| news."#{key}" = value }
fields.each_pair {|key, value| “#{news.key}” = value }
fields.each_pair {|key, value| “news.#{key} = #{value}” }
fields.each_pair {|key, value| news.send key = value }
How do I do this?
Thanks, Elliott