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

  <p>
    <%= f.label :post_id %><br />
    <%= f.text_field :post_id %>
  </p>
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.submit 'Update' %>
  </p>
<% end %>

--------->index.html.erb
 <tr>
    <th>Post</th>
    <th>Name</th>
    <th>Body</th>
  </tr>

<% @comments.each do |comment| %>
  <tr>
    <td><%=h comment.post_id %></td>
    <td><%=h comment.name %></td>
    <td><%=h comment.body %></td>
    <td><%= link_to 'Show', comment %></td>
    <td><%= link_to 'Edit', edit_comment_path(comment) %></td>
    <td><%= link_to 'Destroy', comment, :confirm => 'Are you sure?',
:method => :delete %></td>
  </tr>
<% end %>

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

  <p>
    <%= f.label :post_id %><br />
    <%= f.text_field :post_id %>
  </p>
 <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :body %><br />
    <%= f.text_area :body %>
  </p>
  <p>
    <%= f.submit 'Create' %>
  </p>
<% end %>

------------->show.html.erb
<p>
  <b>Post:</b>
  <%=h @comment.post_id %>
</p>
<p>
  <b>Name:</b>
  <%=h @comment.name %>
</p>
<p>
  <b>Body:</b>
  <%=h @comment.body %>
</p>


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

<h2>Comments</h2>
<div id="comments">
  <%= render :partial => @post.comments %>
</div>

<% remote_form_for [...@post, Comment.new] do |f| %>
  <p>
    <%= f.label :name, "Name" %><br />
    <%= f.text_field :name %><br /><br />
    <%= f.label :body, "New comment" %><br />
    <%= f.text_area :body %>
  </p>
  <p><%= f.submit "Add comment" %></p>
<% 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 %>
  <p>
    <strong>Posted <%= time_ago_in_words(comment.created_at) %> ago by
<%= h(comment.name)%> </strong> <br />
    <%= h(comment.body)%>
  </p>
<% 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
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to