Topic: Object#send for activerecord method

Hi,

I have an activerecord object called @employee, which has a method called product_id (the employees table has a product_id field). I need to set this field to something, which I can do like this in irb:
@employee=Employee.find(1)
@employee.product_id=2
@employee.product_id # => 2
However, I need to set this using Object#send, and this is what happens when I try in irb:
@employee=Employee.find(1)
@employee.send("product_id") # => 2
@employee.send("product_id")=3
@employee.product_id # => 2 (from the previous set)
In other words, it appears send is returning the reader method for @employee, but not the setter method. Why is this and is there any way to use send to SET this field? Thanks.

Re: Object#send for activerecord method

The actual method name is "product_id=" so you should do that in your send. You should also include the arguments in your send call. Like this:

@employee = Employee.find(1)
@employee.send('product_id=', 3)

Railscasts - Free Ruby on Rails Screencasts

Re: Object#send for activerecord method

Thanks!  Seems so obvious looking at it now.