Adding New Column

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.

You missed posting the source…

Lets have a look at edit and show views

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…

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.

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 %>

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

2009/8/28 techtimer [email protected]:

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

Colin

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.

techtimer: glad it helped

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs