i have a procedures table and a procedure model - it contain procedure
descriptions as well as procedure codes.
I would like the user to enter a procedure description (eye surgery)
into a test field and then i would like to return the corresponding
procedure code. Does this code look correct? the
‘find_by_procedure_code’ is what confuses me.
@procedure = Procedure.find_by_procedure_code(params[:procedure]
[:code])
On 11/5/07, agilehack [email protected] wrote:
[:code])
This is the same as:
Procedure.find(:first, :conditions => ‘procedure_code=?’,
params[:procedure][:code])
But if you have a description and want to find the corresponding code,
this is not the right query; it’s finding a procedure given it’s code.
If the description field is called “description” then this:
procedure = Procedure.find_by_description(“eye surgery”)
would return the first Procedure whose description is “eye surgery”,
or nil if there is no such procedure. Assuming you found a row,
code = procedure.code
would give you the code for eye surgery.
HTH