Problem with adding a new column to table

hi everyone.
ok i have a little problem. I created a simple blog + comments system. i
followd ryan bates tutorial on that one, maybe you’ve checked that
screencast out once.
anyway, i added a new colum to my comments table by entering “ruby
script/generate migration add_name_to_comment name:string”

and when i look in my migrations file, it seems to have worked:
class AddNameToComment < ActiveRecord::Migration
def self.up
add_column :comments, :name, :string
end

def self.down
remove_column :comments, :name
end
end

I added “name” to every views-comments page:
-----------> edit.html.erb:
<% form_for(@comment) do |f| %>
<%= f.error_messages %>

<%= f.label :post_id %>
<%= f.text_field :post_id %>

<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :body %>
<%= f.text_area :body %>

<%= f.submit 'Update' %>

<% end %>

--------->index.html.erb

Post Name Body

<% @comments.each do |comment| %>

<%=h comment.post_id %> <%=h comment.name %> <%=h comment.body %> <%= link_to 'Show', comment %> <%= link_to 'Edit', edit_comment_path(comment) %> <%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete %> <% end %>

------------>new.html.erb
<% form_for(@comment) do |f| %>
<%= f.error_messages %>

<%= f.label :post_id %>
<%= f.text_field :post_id %>

<%= f.label :name %>
<%= f.text_field :name %>

<%= f.label :body %>
<%= f.text_area :body %>

<%= f.submit 'Create' %>

<% end %>

------------->show.html.erb

Post: <%=h @comment.post_id %>

Name: <%=h @comment.name %>

Body: <%=h @comment.body %>

So far, so good.
I have tagged comments on the post-pages by adding “has_many” to the
post model, and “belongs_to” to the comment model.

and I use an AJAX remote_form_for for putting the comments-creator on
the posts’ show page:
<%= render :partial => @post %>

Comments

<%= render :partial => @post.comments %>

<% remote_form_for [@post, Comment.new] do |f| %>

<%= f.label :name, "Name" %>
<%= f.text_field :name %>

<%= f.label :body, "New comment" %>
<%= f.text_area :body %>

<%= f.submit "Add comment" %>

<% end %>

Alright. i hope yall can follow. Naturally, i also have a create.js.rjs
file and put javascript on my layouts.rhtml-file.

And lastly, i have a _comment.rhtml file for displaying the comments
under the post on the posts-show page:
<% div_for comment do %>

Posted <%= time_ago_in_words(comment.created_at) %> ago by <%= h(comment.name)%>
<%= h(comment.body)%>

<% end %>

That’s that i want to be displayed on my show-post-page. When the
comment was posted, the name of the creator, and the actual comment.

but for some reason it doesn’t display the newly added “name”, yet it
displays EVERY other column in the comments-table. if put
<%= h(comment.body) instead of <%= h(comment.name), it displays the
comment again, or if i put <%= h(comment.created_at) instead of <%=
h(comment.name), it displays the time it was created. that all works,
EXEPT the name. what’s up with that, i cannot figure out the problem…

I hope my problem isn’t too confusing to understand, and i hope i posted
all relevant code associated to the problem. if i missed some code you
need, just tell me i’ll post it.

JJ

J46 S46 wrote:
[…]

anyway, i added a new colum to my comments table by entering “ruby
script/generate migration add_name_to_comment name:string”

and when i look in my migrations file, it seems to have worked:
class AddNameToComment < ActiveRecord::Migration
def self.up
add_column :comments, :name, :string
end

def self.down
remove_column :comments, :name
end
end

Yes, you’ve got the correct code in your migration file. Now…did you
remember to run the migration?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Marnen Laibow-Koser wrote:

J46 S46 wrote:
[…]

anyway, i added a new colum to my comments table by entering “ruby
script/generate migration add_name_to_comment name:string”

and when i look in my migrations file, it seems to have worked:
class AddNameToComment < ActiveRecord::Migration
def self.up
add_column :comments, :name, :string
end

def self.down
remove_column :comments, :name
end
end

Yes, you’ve got the correct code in your migration file. Now…did you
remember to run the migration?

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Yeah, i did. sorry, forgot to mention that…

Sorry if this sounds primitive but if there was a problem with your
migration your form_for would throw an error about missing the name
field, so I suspect something is cached or the server needs a restart

I would guess that you either need to restart your mongrel server, or
whichever server you have running the application, and you ran rake
db:migrate right? What server are your running under?

Otherwise I wouldtry
script/console

and then just type

Comment

or
Comment.new

see if the name attribute is there.

Also I would try adding some other text to your erb files to make sure
they are updating…?