Can I access an object attribute dynamically using a variable as the field name?
Not sure exactly how to put this, but I want to assign a value to an attribute of an object (e.g. part.partnumber) using a dynamic name for the attribute (a variable of type String). It seems like I should be able to, but I can’t seem to figure it out. Any help would be appreciated. Here’s some code to illustrate what I have tried so far…
Create a field name and find a part
fieldname = “partnumber”
part = Part.find(params[:id])