I want to use a value entered in by a user in an object's form to look
up another value in a reference table and assign that value to the
corresponding attribute in the object. How do I do that?
Right now I have in my controller create method:
if @number = Work.find_by_sql( "SELECT inv FROM
samples_development.works WHERE worknbr REGEXP '" +
@sample['work_number'] + "';" )
@sample.inv = @number
end
But it assigns something odd to the number attribute that looks like
this:
I want to use a value entered in by a user in an object's form to look
up another value in a reference table and assign that value to the
corresponding attribute in the object. How do I do that?
Right now I have in my controller create method:
if @number = Work\.find\_by\_sql\( "SELECT inv FROM
samples_development.works WHERE worknbr REGEXP '" +
@sample['work_number'] + "';" )
find_by_sql always returns an array of instances of the corresponding
class (Work in this case) no matter what the select clause is. The
columns in the result set are all there as attributes though