# Adding New Column

**URL:** <https://www.ruby-forum.com/t/adding-new-column/174515>\
**Category:** Rails\
**Created:** [August 27, 2009, 11:38pm UTC](https://www.ruby-forum.com/t/adding-new-column/174515 "2009-08-27T23:38:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 27, 2009, 11:38pm UTC](https://www.ruby-forum.com/t/adding-new-column/174515/1 "2009-08-27T23:38:14Z")

</div>

I added a new column using a migration. Once I updated the  
new.html.erb, edit.html.erb, show.html.erb, and the index.html.erb I  
brought up my web pages. There was a field to update show. I tried the  
update and the it was successful but the update did not show up in any  
of the other pages. What did I miss? I am using 2.3.3 of ror.

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 27, 2009, 11:49pm UTC](https://www.ruby-forum.com/t/adding-new-column/174515/2 "2009-08-27T23:49:22Z")

</div>

You missed posting the source…

Lets have a look at edit and show views

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 28, 2009, 12:23am UTC](https://www.ruby-forum.com/t/adding-new-column/174515/3 "2009-08-28T00:23:54Z")

</div>

The table I am working with is contacts. The new column is type. I  
changed the edit.html.erb source by adding.

\<%= f.label :type %\>  
 \<%= f.text\_field :type %\>

In the show.html.erb I added

**Type:** \<%=h @contact.type %.

What else do I need to post the source…

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 28, 2009, 2:36am UTC](https://www.ruby-forum.com/t/adding-new-column/174515/4 "2009-08-28T02:36:49Z")

</div>

I think the problem is with the name of the column, :type. It’s a  
reserved. I read there is a way to use it, but I say it’s really not  
worth it. Try dropping the column and adding it with different name.  
Should work.

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 28, 2009, 12:43am UTC](https://www.ruby-forum.com/t/adding-new-column/174515/5 "2009-08-28T00:43:48Z")

</div>

Sorry, I didn’t understand what you meant by post your code. I  
snapped, finally. Here it is. Thanks for your help.  
Again the table is contacts and the field I added is type.

edt.html.erb

# Editing contact

\<% form\_for(@contact) do |f| %\>  
\<%= f.error\_messages %\>

\<%= f.label :user\_id %\>  
 \<%= f.text\_field :user\_id %\>

\<%= f.label :is\_owner %\>  
 \<%= f.check\_box :is\_owner %\>

\<%= f.label :first\_name %\>  
 \<%= f.text\_field :first\_name %\>

\<%= f.label :mid\_init %\>  
 \<%= f.text\_field :mid\_init %\>

\<%= f.label :last\_name %\>  
 \<%= f.text\_field :last\_name %\>

\<%= f.label :title %\>  
 \<%= f.text\_field :title %\>

\<%= f.label :company %\>  
 \<%= f.text\_field :company %\>

\<%= f.label :phone %\>  
 \<%= f.text\_field :phone %\>

\<%= f.label :email %\>  
 \<%= f.text\_field :email %\>

\<%= f.label :logo %\>  
 \<%= f.text\_field :logo %\>

\<%= f.label :type %\>  
 \<%= f.text\_field :type %\>

\<%= f.submit "Update" %\>

\<% end %\>

\<%= link\_to ‘Show’, @contact %\> |  
\<%= link\_to ‘Back’, contacts\_path %\>

show.html.erb

**User:** \<%=h @contact.user\_id %\>

**Is owner:** \<%=h @contact.is\_owner %\>

**First name:** \<%=h @contact.first\_name %\>

**Mid init:** \<%=h @contact.mid\_init %\>

**Last name:** \<%=h @contact.last\_name %\>

**Title:** \<%=h @contact.title %\>

**Company:** \<%=h @contact.company %\>

**Phone:** \<%=h @contact.phone %\>

**Email:** \<%=h @contact.email %\>

**Logo:** \<%=h @contact.logo %\>

**Type:** \<%=h @contact.type %\>

\<%= link\_to ‘Edit’, edit\_contact\_path(@contact) %\> |  
\<%= link\_to ‘Back’, contacts\_path %\>

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 28, 2009, 3:34am UTC](https://www.ruby-forum.com/t/adding-new-column/174515/6 "2009-08-28T03:34:11Z")

</div>

Thank you. I removed type and created a new field. Everything is  
working great thanks for your help.

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 28, 2009, 9:59am UTC](https://www.ruby-forum.com/t/adding-new-column/174515/7 "2009-08-28T09:59:55Z")

</div>

2009/8/28 techtimer [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Thank you. I removed type and created a new field. Everything is  
> working great thanks for your help.

For future reference a list of words to avoid can be found at  
[http://wiki.rubyonrails.org/rails/pages/ReservedWords](http://wiki.rubyonrails.org/rails/pages/ReservedWords)

Colin

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 28, 2009, 3:10pm UTC](https://www.ruby-forum.com/t/adding-new-column/174515/8 "2009-08-28T15:10:46Z")

</div>

Bashar A. wrote:

> I think the problem is with the name of the column, :type. It’s a  
> reserved.

Just to clarify, ActiveRecord assumes a column named type is used for  
Single Table Inheritance. You can configure the model to tell  
ActiveRecord to use a different column name for that purpose, which  
would then allow you to use a column named :type. But, the simpler  
solution is to avoid using :type.

---

<div class="post-metadata">

**Author:** ![techtimer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@techtimer](https://www.ruby-forum.com/u/techtimer)\
**Post date:** [August 29, 2009, 10:42am UTC](https://www.ruby-forum.com/t/adding-new-column/174515/9 "2009-08-29T10:42:39Z")

</div>

techtimer: glad it helped

Colin L. & Robert W.: Thanks for the tips. I recall now reading  
about the STI.
