# Scaffolds, Multiple Tables, and Key Fields

**URL:** <https://www.ruby-forum.com/t/scaffolds-multiple-tables-and-key-fields/122380>\
**Category:** Rails\
**Created:** [December 7, 2007, 4:21am UTC](https://www.ruby-forum.com/t/scaffolds-multiple-tables-and-key-fields/122380 "2007-12-07T04:21:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 7, 2007, 4:21am UTC](https://www.ruby-forum.com/t/scaffolds-multiple-tables-and-key-fields/122380/1 "2007-12-07T04:21:38Z")

</div>

Is there a simple way to edit two tables with a has\_many/belongs\_to  
relationship? I have a very typical parent table (Departments) with  
an id, name, description, etc. And I have a child Resources table  
with an id, department\_id, title, description, and other fields.

I want to allow a user to edit the child table but I see that the  
standard behavior for scaffolds is to suppress displaying key fields  
(primary and foreign) is there a way to override this?

Basically when I’m editing the child record I really need to display  
the Department.title. I know I can do this by hand, but I’d like  
the scaffolding to help me if possible! is it?

Thanks,

Gary H.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 7, 2007, 10:14am UTC](https://www.ruby-forum.com/t/scaffolds-multiple-tables-and-key-fields/122380/2 "2007-12-07T10:14:51Z")

</div>

Check out the 3-part screencast on complex forms at [railscasts.com](http://railscasts.com)  
starting with #73  
[#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73)

This will walk you through setting up editing two forms at once if you  
want something more complex.

On Dec 6, 9:21 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Basically when I’m editing the child record I really need to display  
> the Department.title. I know I can do this by hand, but I’d like  
> the scaffolding to help me if possible! is it?

I don’t know of a way for Scaffold to do it, possibly ActiveScaffold  
would. [http://activescaffold.com/](http://activescaffold.com/)

or just In your Resources (that’s the child right?) view, use this in  
your \_form  
\<%= collection\_select :resource, :department\_id,  
Department.find(:all), :id, :name %\>

Read more about collection\_select here:

> **[ActionView::Helpers::FormOptionsHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#M000928)**
>
> Provides a number of methods for turning different kinds of containers into a set of option tags.

it puts in department\_id of a resource from what was collected from  
all department listings and give you a select field with id of  
department as a value and name of department as text.

and in your list use \<%= resource.department.name %\> inside the for  
statement, and in show \<%= @resource.department.name %\> anywhere.
