On 15 March 2012 16:27, Groovor C.
<lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> I have ajax based micropost''s comments on the user page. It works,
but
> not correctly. When I submit a new comment to ANY micropost, it always
> posts to the LAST micropost! Then, if I refresh the page by "F5",
> everything falls into place - the new comment is in the correct
> micropost. What I''m doing wrong? Thanks in advance.
First look in development.log and check that the correct parameters
are being passed in.  Then have a look at the Rails Guide on Debugging
which will show you a number of techniques that can be used to debug
the code.
Colin
>
> comment.rb
>
> class Comment < ActiveRecord::Base
>  attr_accessible :comment_content
>  belongs_to :user
>  belongs_to :micropost
> end
>
>
> comments_controller.rb
>
> class CommentsController < ApplicationController
>  before_filter :signed_in_user, only: [:create, :destroy]
>
>   def create
>    @micropost = Micropost.find(params[:micropost_id])
>    @comment = Comment.new(params[:comment])
>    -I4CJOCdi0N7Mo/R2UJeS816hYfS7NtTn@public.gmane.org = @micropost
>    -I4CJOCdi0N4BB6bauf/WkQ@public.gmane.org = current_user
>      respond_to do |format|
>      -I4CJOCdi0N5LYScDn9snng@public.gmane.org
>           format.html { redirect_to current_user }
>           format.js
>      end
>   end
> end
>
>
> _micropost.html.erb
>
> <tr>
>  <td class="micropost">
>    <span class="content"><%= wrap(micropost.content)
%></span>
>    <span class="timestamp">
>    Posted <%= time_ago_in_words(micropost.created_at) %> ago.
>    </span>
>    <%= render ''shared/comment_form'', micropost:
micropost %>
>   <div id="comments">
>     <%= render micropost.comments %>
>   </div>
>  </td>
> </tr>
>
>
> _comment_form.html.erb
>
> <%= form_for ([micropost, @comment]), :remote => true do |f| %>
> <%= render ''shared/error_messages'', object: f.object
%>
> <%= f.text_area :comment_content, :size => "40x2" %>
>  <button class="btn" type="submit">
>    Comment
>  </button>
> <% end %>
>
>
> _comment.html.erb
>
> <span style="width: 100%; background:#dff0d8"><%>
wrap(comment.comment_content) %></span>
> <span class="timestamp">
>  Posted by <%= comment.user.name %> <%>
time_ago_in_words(comment.created_at) %> ago.
> </span>
>
>
> create.js.erb
>
> $(''#comments'').html("<%=
escape_javascript(render(:partial =>
> @micropost.comments)) %>");
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
>
-- 
gplus.to/clanlaw
-- 
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@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.