Fix comments ajax response
This commit is contained in:
parent
4e15745170
commit
845e1fe7a3
5 changed files with 16 additions and 19 deletions
|
|
@ -18,14 +18,22 @@ class CommentsController < ApplicationController
|
|||
if @comment.save(:safe => true)
|
||||
raise 'MongoMapper failed to catch a failed save' unless @comment.id
|
||||
Rails.logger.info("event=comment_create user=#{current_user.diaspora_handle} status=success comment=#{@comment.id}")
|
||||
|
||||
current_user.dispatch_comment(@comment)
|
||||
|
||||
respond_to do |format|
|
||||
format.js{ render :json => { :post_id => @comment.post_id,
|
||||
format.js{
|
||||
json = { :post_id => @comment.post_id,
|
||||
:comment_id => @comment.id,
|
||||
:html => render_to_string(:partial => type_partial(@comment), :locals => {:comment => @comment, :person => current_user, :current_user => current_user})},
|
||||
:status => 201 }
|
||||
:html => render_to_string(
|
||||
:partial => 'comments/comment',
|
||||
:locals => {
|
||||
:comment => @comment,
|
||||
:person => current_user,
|
||||
}
|
||||
)
|
||||
}
|
||||
render(:json => json, :status => 201)
|
||||
}
|
||||
format.html{ render :nothing => true, :status => 201 }
|
||||
end
|
||||
else
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ module SocketsHelper
|
|||
elsif object.is_a? Person
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:single_aspect_form => opts[:single_aspect_form], :person => object, :aspects => user.aspects, :current_user => user})
|
||||
elsif object.is_a? Comment
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:comment => object, :person => object.person, :current_user => user})
|
||||
v = render_to_string(:partial => 'comments/comment', :locals => {:comment => object, :person => object.person})
|
||||
else
|
||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,23 +3,11 @@
|
|||
-# the COPYRIGHT file.
|
||||
|
||||
%li.comment{:data=>{:guid=>comment.id}}
|
||||
/-start=Time.now
|
||||
%a{:href => "/people/#{person.id}"}
|
||||
%img{:src => image_or_default(person), :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id}
|
||||
/- post_image_link=Time.now
|
||||
.content
|
||||
.from
|
||||
%a{:href => "/people/#{person.id}"}=person.real_name
|
||||
/- post_person_link=Time.now
|
||||
= markdownify(comment.text, :youtube_maps => comment[:youtube_titles])
|
||||
/- markdownified=Time.now
|
||||
%div.time
|
||||
= "#{time_ago_in_words(comment.updated_at)} #{t('ago')}"
|
||||
/- time_agoed=Time.now
|
||||
/- log_string = "event=comment_partial im_link=#{(post_image_link - start)*1000} "
|
||||
/- log_string << "pr_link=#{(post_person_link - post_image_link)*1000} "
|
||||
/- log_string << "markdown=#{(markdownified - post_person_link)*1000} "
|
||||
/- log_string << "time_agoed=#{(time_agoed - markdownified)*1000} "
|
||||
/- log_string << "total=#{(time_agoed - start)*1000} "
|
||||
/- log_string << "comment_id=#{comment.id}"
|
||||
/- Rails.logger.info(log_string)
|
||||
= comment.created_at ? "#{time_ago_in_words(comment.created_at)} #{t('ago')}" : time_ago_in_words(Time.now)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
-# licensed under the Affero General Public License version 3 or later. See
|
||||
-# the COPYRIGHT file.
|
||||
|
||||
= form_tag( comments_path, :id => "new_comment_on_#{post_id}" , :remote => true) do
|
||||
= form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do
|
||||
%p
|
||||
= label_tag "comment_text_on_#{post_id}", t('.comment')
|
||||
= text_area_tag :text, nil, :rows => 1, :class => "comment_box",:id => "comment_text_on_#{post_id}"
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ describe CommentsController do
|
|||
it 'responds to format js' do
|
||||
post :create, comment_hash.merge(:format => 'js')
|
||||
response.code.should == '201'
|
||||
response.body.should match comment_hash[:text]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue