Having trouble writing the right view to generate the desire

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

  1. Enter new claim data

  2. <%= error_messages_for :claim %>
  3. <% form_for :claim, :url => claims_path do |f| %>
  4. Patient Number:
    
  5. <%= 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.

On Sep 28, 6:39 am, Max B. [email protected]
wrote:

So patient_number is an attribute of the patient that owns the claim,
not an attribute of the claim itself.

I think it’s your use of the :index option that is giving you the
current output instead of the second variant. For the third variant,
just use text_field_tag.

Fred

Both suggestions did exactly what you said. Thank you.

Now of course I’m having trouble with the default fields in edit. I’ve
changed edit.html.erb so that editing an existing claim works.

Here’s my edit.html.erb

Edit Claim's Information

<%= “Enter claim number #{h(@claim.claim_number)}'s information.” %>

<% form_for :claim, :url => claim_path(params[:id]),
:html => {:method => :put} do |f| %>

Patient Number: <%= text_field_tag :patient_number %>

Doctor Number: <%= text_field_tag :doctor_number %>

Procedure Code: <%= f.text_field :procedure_code %>

Date Performed: <%= f.text_field :date_performed %>

Doctor Filed: <%= f.text_field :date_filed %>

<%= submit_tag "Save Changes" %> <% end %> <%= link_to "Or go back to claim information.", claim_path(:id => @claim.id) %>

Is there some way to manually set what the default text is in a text
field?