Topic: Access dynamic model attributes

Hi all,

I'm trying to find a way of dynamically accessing a Product.name and Product.permalink data

I have something like this so far:

["name", "permalink"].each do |prop|
     product.prop = "test"
  end

But I'm getting this error message: undefined method `prop=' for #<Product:0x5643f18>

Many thanks in advance

Zap

Re: Access dynamic model attributes

Use Object.send.

 ["name", "permalink"].each do |prop|
     product.send(prop + "=", "test")
 end