# After migration, how to see new columns?

**URL:** <https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758>\
**Category:** Rails\
**Created:** [September 4, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758 "2007-09-04T19:12:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mtaplits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mtaplits](https://www.ruby-forum.com/u/mtaplits)\
**Post date:** [September 4, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758/1 "2007-09-04T19:12:21Z")

</div>

New to rails so please bear with me. I used migrations to add a column  
to an existing table. The new column is added to the database  
successfully. However when I go to ‘list’ the items, the new column  
isn’t displayed. When I go to ‘create’ a new item, the new column is  
displayed and when entered, saves to the new database column correctly.  
How can I get the column to ‘list’ as well?

---

<div class="post-metadata">

**Author:** ![mtaplits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mtaplits](https://www.ruby-forum.com/u/mtaplits)\
**Post date:** [September 4, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758/2 "2007-09-04T20:00:10Z")

</div>

Have you tried restarting the server?

---

<div class="post-metadata">

**Author:** ![mtaplits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mtaplits](https://www.ruby-forum.com/u/mtaplits)\
**Post date:** [September 5, 2007, 1:26am UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758/3 "2007-09-05T01:26:52Z")

</div>

Adding a column in a migration won’t make rails add the necessary view  
code to show it. That’s up to you.

Rein  
[http://reinh.com](http://reinh.com)

On Sep 4, 12:12 pm, Marshall T. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![mtaplits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mtaplits](https://www.ruby-forum.com/u/mtaplits)\
**Post date:** [September 5, 2007, 1:33am UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758/4 "2007-09-05T01:33:33Z")

</div>

Thanks for your reply. What’s interesting is that I did change the  
\_form view and when I go to create a new item, the new column does show  
and save to the database. However, list and edit don’t show the new  
column. They don’t seem to have separate views, all calling on the same  
\_form.

Any ideas?

Thanks!

Rein H. wrote:

> Adding a column in a migration won’t make rails add the necessary view  
> code to show it. That’s up to you.
> 
> Rein  
> [http://reinh.com](http://reinh.com)
> 
> On Sep 4, 12:12 pm, Marshall T. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![mtaplits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mtaplits](https://www.ruby-forum.com/u/mtaplits)\
**Post date:** [September 5, 2007, 1:41am UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758/5 "2007-09-05T01:41:54Z")

</div>

On 9/4/07, Marshall T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks for your reply. What’s interesting is that I did change the  
> \_form view and when I go to create a new item, the new column does show  
> and save to the database. However, list and edit don’t show the new  
> column. They don’t seem to have separate views, all calling on the same  
> \_form.

are you absolutely sure that create and edit are both calling render  
:partial =\> ‘form’ to display the new/edit form?

And list should be a different view and usually doesn’t render the  
form that create and edit use, since it’ll be a list of your items.  
To include your new colum in the list view, just do something like

\<%= @object.my\_new\_column %\>

Adam

---

<div class="post-metadata">

**Author:** ![mtaplits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mtaplits](https://www.ruby-forum.com/u/mtaplits)\
**Post date:** [September 5, 2007, 6:40am UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758/6 "2007-09-05T06:40:38Z")

</div>

Thanks Adam. I’m attaching a document with screenshots of my situation  
since I still can’t get it to work properly. Again, apologize since I’m  
new to Rails but being able to migrate a database to a new version and  
having the new columns show up in my views is critical for progress :).  
Appreciate any help you all may be able to provide.

Adam C. wrote:

> On 9/4/07, Marshall T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Thanks for your reply. What’s interesting is that I did change the  
> > \_form view and when I go to create a new item, the new column does show  
> > and save to the database. However, list and edit don’t show the new  
> > column. They don’t seem to have separate views, all calling on the same  
> > \_form.
> 
> are you absolutely sure that create and edit are both calling render  
> :partial =\> ‘form’ to display the new/edit form?
> 
> And list should be a different view and usually doesn’t render the  
> form that create and edit use, since it’ll be a list of your items.  
> To include your new colum in the list view, just do something like
> 
> \<%= @object.my\_new\_column %\>
> 
> Adam

---

<div class="post-metadata">

**Author:** ![mtaplits](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/5f8ce5/32.png) [@mtaplits](https://www.ruby-forum.com/u/mtaplits)\
**Post date:** [September 5, 2007, 7:20am UTC](https://www.ruby-forum.com/t/after-migration-how-to-see-new-columns/113758/7 "2007-09-05T07:20:21Z")

</div>

On 9/4/07, Marshall T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Thanks Adam. I’m attaching a document with screenshots of my situation  
> since I still can’t get it to work properly. Again, apologize since I’m  
> new to Rails but being able to migrate a database to a new version and  
> having the new columns show up in my views is critical for progress :).  
> Appreciate any help you all may be able to provide.

Are you absolutely sure you restarted your webserver process?  
Everything looks good to me. Keep in mind that Class.content\_columns  
won’t retrieve _every_ column in your database. For example, foreign  
key attributes will not be retrieved (are project and vendor actually  
project\_id and vendor\_id ?), and it seems that columns with the word  
‘count’ in them won’t be returned either. In any case, an easy way to  
solve this is to start replacing the scaffolding code with real code  
(scaffolding is really just meant as a starting point anyways).

So instead of using:

 \<% for column in Item.content\_columns %\> \<% end %\> ....

| \<%= column.human\_name %\> |
| --- |

you can do the following:

controller.rb:  
@items = Item.find(:all)

in your view.rhtml:

... \<% for item in @items %\> \<% end %\>

| Project | Vendor | SKU | Name |
| --- | --- | --- | --- |
| \<%= item.project %\>\</t |

Hope this helps

Adam
