# How to write a test hash for a nested form?

**URL:** <https://www.ruby-forum.com/t/how-to-write-a-test-hash-for-a-nested-form/195918>\
**Category:** Rails\
**Created:** [October 2, 2010, 10:01pm UTC](https://www.ruby-forum.com/t/how-to-write-a-test-hash-for-a-nested-form/195918 "2010-10-02T22:01:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ntk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@ntk](https://www.ruby-forum.com/u/ntk)\
**Post date:** [October 2, 2010, 10:01pm UTC](https://www.ruby-forum.com/t/how-to-write-a-test-hash-for-a-nested-form/195918/1 "2010-10-02T22:01:01Z")

</div>

How to write a hash for a nested form??

Example form fields (main model is Practice, nested is User):  
practice[name]  
practice[users\_attributes][0][email]

I want to do this:

post:  
post :create, :practice =\> { :name =\> “any name”, :users\_attributes =\>  
{  
:0 =\> { :email =\> “removed\_email\_address@domain.invalid” } } }

The issue is that I can not create a symbol for 0 - :0 and :0.to\_sym  
don’t  
work and “0”.to\_sym and ‘0’.to\_sym give me the weird :“0”. So how can I  
hack  
this through? Is there another way to create such a hash which bypasses  
need  
for symbols which the controller will still understand?

Thanks,

David

---

<div class="post-metadata">

**Author:** ![ntk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@ntk](https://www.ruby-forum.com/u/ntk)\
**Post date:** [October 3, 2010, 10:59am UTC](https://www.ruby-forum.com/t/how-to-write-a-test-hash-for-a-nested-form/195918/2 "2010-10-03T10:59:17Z")

</div>

You do not need it to be symbols I guess. I think that string will  
work just fine.  
Anyway. You can create symbols also this way:

:“123”

Robert Pankowecki

---

<div class="post-metadata">

**Author:** ![ntk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/48db29/32.png) [@ntk](https://www.ruby-forum.com/u/ntk)\
**Post date:** [October 3, 2010, 9:51pm UTC](https://www.ruby-forum.com/t/how-to-write-a-test-hash-for-a-nested-form/195918/3 "2010-10-03T21:51:54Z")

</div>

Thanks Robert, that worked great. Just looks a little weird at first to  
do  
:“0”.

On Sun, Oct 3, 2010 at 3:57 AM, Robert Pankowecki (rupert) \<
