jdgriffith
2010-Jan-05 23:59 UTC
Problem with associating comments with blog posts on same page
Hi, I will admit I am very new to ruby and I am trying to do something that is not in any tutorials I have found. If you see a more conventional way to do some of the things I am trying to do, please let me know. What I am trying to accomplish. People can edit the comments on the same page as the listing of posts. The problem is that when I go to create the comment, it is not getting associated with the post. I have accomplished this on other pages through normal methods such as: app/views/posts/show.html.erb <% form_for [@post, Comment.new] do |f| %> This successfully pulls the post id and saves the comment as belonging to that post. Now, when I try to incorporate everything all into a very easy page to navigate I can''t use the same code associations and my comments fail. app/views/posts/index.html.erb <% div_for( post ) do %> <h3><%= link_to_unless_current h(post.title), statemant %></h3> <p class="timestamp"> Posted <%=h time_ago_in_words(post.created_at) %> ago </p> <p> Approved: <%= h(post.approved) %> </p> <p class="post_post"> <%= simple_format h(post.body) %> </p> <% randomNumber = rand(100000) %> <img src="/images/add_comment.jpg" class="add_comment_image<%randomNumber %>" /> <div id="comments<%= randomNumber %>"> <%= render :partial => post.comments %> <h1>New comment</h1> <% form_for :comment, :url => { :controller => "comments", :action => :create} do |f| %> <%= f.error_messages %> <%= f.hidden_field(:post_id, :value => post.post_id) %> <p> <%= f.text_area :body %> </p> <p> <%= f.submit ''Add your Comment'' %> </p> <% end %> </div> <% end %> Thanks for any help or pointers. I hope that you can understand what I am trying to accomplish. Justin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.