On 11/5/07, agilehack
<jason.rabolli-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> 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])
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---