# Having trouble writing the right view to generate the desire

**URL:** <https://www.ruby-forum.com/t/having-trouble-writing-the-right-view-to-generate-the-desire/149687>\
**Category:** Rails\
**Created:** [September 28, 2008, 7:39am UTC](https://www.ruby-forum.com/t/having-trouble-writing-the-right-view-to-generate-the-desire/149687 "2008-09-28T07:39:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxbohr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f4b2a3/32.png) [@maxbohr](https://www.ruby-forum.com/u/maxbohr)\
**Post date:** [September 28, 2008, 7:39am UTC](https://www.ruby-forum.com/t/having-trouble-writing-the-right-view-to-generate-the-desire/149687/1 "2008-09-28T07:39:31Z")

</div>

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. 
4. \<% form\_for :claim, :url =\> claims\_path do |f| %\>
5. 

6. 

```
Patient Number:

```

7. 

```
<%= 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.

---

<div class="post-metadata">

**Author:** ![maxbohr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f4b2a3/32.png) [@maxbohr](https://www.ruby-forum.com/u/maxbohr)\
**Post date:** [September 28, 2008, 11:32am UTC](https://www.ruby-forum.com/t/having-trouble-writing-the-right-view-to-generate-the-desire/149687/2 "2008-09-28T11:32:51Z")

</div>

On Sep 28, 6:39 am, Max B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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

---

<div class="post-metadata">

**Author:** ![maxbohr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f4b2a3/32.png) [@maxbohr](https://www.ruby-forum.com/u/maxbohr)\
**Post date:** [September 28, 2008, 6:53pm UTC](https://www.ruby-forum.com/t/having-trouble-writing-the-right-view-to-generate-the-desire/149687/3 "2008-09-28T18:53:09Z")

</div>

Both suggestions did exactly what you said. Thank you.

---

<div class="post-metadata">

**Author:** ![maxbohr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f4b2a3/32.png) [@maxbohr](https://www.ruby-forum.com/u/maxbohr)\
**Post date:** [September 29, 2008, 3:25am UTC](https://www.ruby-forum.com/t/having-trouble-writing-the-right-view-to-generate-the-desire/149687/4 "2008-09-29T03:25:56Z")

</div>

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?
