# Automatically filling values in a form

**URL:** <https://www.ruby-forum.com/t/automatically-filling-values-in-a-form/145010>\
**Category:** Rails\
**Created:** [August 5, 2008, 6:17am UTC](https://www.ruby-forum.com/t/automatically-filling-values-in-a-form/145010 "2008-08-05T06:17:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [August 5, 2008, 6:17am UTC](https://www.ruby-forum.com/t/automatically-filling-values-in-a-form/145010/1 "2008-08-05T06:17:33Z")

</div>

I have 2 models: parent & child

parent has\_many children and child belongs\_to parent

When a parent is created, the user has the chance to click on parent  
and add a new child. I want to automatically pass back the parent\_id  
back to the controller, without making it part of the form.

How can this be accomplished?

The tables look like this:  
parent:  
id  
name

child:  
id  
name  
parent\_id \<-- this needs to be automatically filled based off the  
selected parent.

I can get as far as verifying that I have the correct parent instance  
in create child controller, but I just can’t get the parent\_id to be  
passed into the controller…

---

<div class="post-metadata">

**Author:** ![mike](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/58f4c7/32.png) [@mike](https://www.ruby-forum.com/u/mike)\
**Post date:** [August 5, 2008, 10:44am UTC](https://www.ruby-forum.com/t/automatically-filling-values-in-a-form/145010/2 "2008-08-05T10:44:53Z")

</div>

> When a parent is created, the user has the chance to click on parent  
> and add a new child. I want to automatically pass back the parent\_id  
> back to the controller, without making it part of the form.

Why don’t you want to make it part of the form?  
Can’t see a reason, to make it a hidden\_field like:

\<%= f.hidden\_field(parent\_id) %\>

or something the like.

Otherwise pass it with the url:

\<% form\_for(@child, :url =\> child\_path(:parent\_id =\>  
@my\_parent\_if\_from\_controller\_or\_whatever)) do |f| %\>
