objects and attributes

I have this method that it's soul purpose is to toggle a field and then
redisplay a chech_box helper and a image signifying that the field has
been updated. My issue, however, is that this method is to toggle
several different field all via one method simply because the code to do
so was all the same code save for the name of the field. I pass a value
in which is the name of the field that I am manipulating, for example:

def method_1(attribute_name)
.....
end

In that method I find a user based on an id and then I need to set an
attribute based on the value passed in, so I have:

@user.find_by_id(params[:id])

@user."#{attribute_name}"

However, that last bit of code doesn't work. Is there a way to do what I
am trying to do, that is, use dot notion on an object to update a field
whose value is being passed into the method? Thanks in advance,

-S

try to do

@user[attribute_name] = value

if you pass a string or a symbol =]

@user."#{attribute_name}"

However, that last bit of code doesn't work. Is there a way to do
what I
am trying to do, that is, use dot notion on an object to update a
field
whose value is being passed into the method? Thanks in advance,

You can use send to call methods by name.

Fred

Fabio Eidi wrote:

try to do

@user[attribute_name] = value

if you pass a string or a symbol =]

That did the trick. Thx,

-S