I’m doing a small toy app to learn rails, and I ran into some difficulty
with one of my views, specifically with the parameters hash that is
returned to me during the create action
Currently, given the form I have now, I get the following two hashes to
appear among my parameters.
“claim”=>{“date_filed”=>“04/06/2008”,
“doctor_number”=>“D53475”,
“procedure_code”=>“51551”,
“date_performed”=>“04/03/2008”},
“patient_query”=>{“patient”=>{“patient_number”=>“F23793”}}}
Ideally, I’d like my parameters to be
“claim”=>{“date_filed”=>“04/06/2008”,
“doctor_number”=>“D53475”,
“procedure_code”=>“51551”,
“date_performed”=>“04/03/2008”},
“patient_query”=>{“patient_number”=>“F23793”}}
or cleanest of all would be
“claim”=>{“date_filed”=>“04/06/2008”,
“doctor_number”=>“D53475”,
“procedure_code”=>“51551”,
“date_performed”=>“04/03/2008”},
“patient_number”=>“F23793”
Here’s the view code I have now for new.html.erb
-
Enter new claim data
- <%= error_messages_for :claim %>
- <% form_for :claim, :url => claims_path do |f| %>
-
-
Patient Number:
-
<%= text_field :patient_query, :patient_number, :index =>
:patient %>
8.
9.
10. Doctor Number:
11. <%= f.text_field :doctor_number %>
12.
13.
14. Procedure Code:
15. <%= f.text_field :procedure_code %>
16.
17.
18. Date Performed:
19. <%= f.text_field :date_performed %>
20.
21.
22. Doctor Filed:
23. <%= f.text_field :date_filed %>
24.
25. <%= submit_tag “Create Claim” %>
26. <% end %>
27. <%= link_to “Or go back to all claims.”,
28. doctors_path %>
My motivation for doing things this way is that I have a patient model
and a claim model and a patient has many claims. Each patient has a
unique identifier (different from the standard id), and I am going to
search the database for the patient with this patient_number and set the
claim’s pateint_id attribute to the id number of the found patient.
So patient_number is an attribute of the patient that owns the claim,
not an attribute of the claim itself.
Any help would be appreciated.