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
<% @comments.each do |comment| %>
------------>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
<% 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)%>
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