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.
<p> <%= f.label :type %><br /> <%= f.text_field :type %> </p>
In the show.html.erb I added
<p> <b>Type:</b> <%=h @contact.type %. </p>
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
<h1>Editing contact</h1>
<% form_for(@contact) do |f| %> <%= f.error_messages %>
<p> <%= f.label :user_id %><br /> <%= f.text_field :user_id %> </p> <p> <%= f.label :is_owner %><br /> <%= f.check_box :is_owner %> </p> <p> <%= f.label :first_name %><br /> <%= f.text_field :first_name %> </p> <p> <%= f.label :mid_init %><br /> <%= f.text_field :mid_init %> </p> <p> <%= f.label :last_name %><br /> <%= f.text_field :last_name %> </p> <p> <%= f.label :title %><br /> <%= f.text_field :title %> </p> <p> <%= f.label :company %><br /> <%= f.text_field :company %> </p> <p> <%= f.label :phone %><br /> <%= f.text_field :phone %> </p> <p> <%= f.label :email %><br /> <%= f.text_field :email %> </p> <p> <%= f.label :logo %><br /> <%= f.text_field :logo %> </p> <p> <%= f.label :type %><br /> <%= f.text_field :type %> </p> <p> <%= f.submit "Update" %> </p> <% end %>
<%= link_to 'Show', @contact %> | <%= link_to 'Back', contacts_path %>
show.html.erb
<p> <b>User:</b> <%=h @contact.user_id %> </p>
<p> <b>Is owner:</b> <%=h @contact.is_owner %> </p>
<p> <b>First name:</b> <%=h @contact.first_name %> </p>
<p> <b>Mid init:</b> <%=h @contact.mid_init %> </p>
<p> <b>Last name:</b> <%=h @contact.last_name %> </p>
<p> <b>Title:</b> <%=h @contact.title %> </p>
<p> <b>Company:</b> <%=h @contact.company %> </p>
<p> <b>Phone:</b> <%=h @contact.phone %> </p>
<p> <b>Email:</b> <%=h @contact.email %> </p>
<p> <b>Logo:</b> <%=h @contact.logo %> </p>
<p> <b>Type:</b> <%=h @contact.type %> </p>
<%= 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.
For future reference a list of words to avoid can be found at http://wiki.rubyonrails.org/rails/pages/ReservedWords
Colin
Bashar Abdullah 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 Law & Robert Walker: Thanks for the tips. I recall now reading about the STI.