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)
|
if @comment.save(:safe => true)
|
||||||
raise 'MongoMapper failed to catch a failed save' unless @comment.id
|
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}")
|
Rails.logger.info("event=comment_create user=#{current_user.diaspora_handle} status=success comment=#{@comment.id}")
|
||||||
|
|
||||||
current_user.dispatch_comment(@comment)
|
current_user.dispatch_comment(@comment)
|
||||||
|
|
||||||
respond_to do |format|
|
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,
|
:comment_id => @comment.id,
|
||||||
:html => render_to_string(:partial => type_partial(@comment), :locals => {:comment => @comment, :person => current_user, :current_user => current_user})},
|
:html => render_to_string(
|
||||||
:status => 201 }
|
:partial => 'comments/comment',
|
||||||
|
:locals => {
|
||||||
|
:comment => @comment,
|
||||||
|
:person => current_user,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
render(:json => json, :status => 201)
|
||||||
|
}
|
||||||
format.html{ render :nothing => true, :status => 201 }
|
format.html{ render :nothing => true, :status => 201 }
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ module SocketsHelper
|
||||||
elsif object.is_a? Person
|
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})
|
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
|
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
|
else
|
||||||
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
|
v = render_to_string(:partial => type_partial(object), :locals => {:post => object, :current_user => user}) unless object.is_a? Retraction
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,23 +3,11 @@
|
||||||
-# the COPYRIGHT file.
|
-# the COPYRIGHT file.
|
||||||
|
|
||||||
%li.comment{:data=>{:guid=>comment.id}}
|
%li.comment{:data=>{:guid=>comment.id}}
|
||||||
/-start=Time.now
|
|
||||||
%a{:href => "/people/#{person.id}"}
|
%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}
|
%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
|
.content
|
||||||
.from
|
.from
|
||||||
%a{:href => "/people/#{person.id}"}=person.real_name
|
%a{:href => "/people/#{person.id}"}=person.real_name
|
||||||
/- post_person_link=Time.now
|
|
||||||
= markdownify(comment.text, :youtube_maps => comment[:youtube_titles])
|
= markdownify(comment.text, :youtube_maps => comment[:youtube_titles])
|
||||||
/- markdownified=Time.now
|
|
||||||
%div.time
|
%div.time
|
||||||
= "#{time_ago_in_words(comment.updated_at)} #{t('ago')}"
|
= comment.created_at ? "#{time_ago_in_words(comment.created_at)} #{t('ago')}" : time_ago_in_words(Time.now)
|
||||||
/- 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)
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
-# licensed under the Affero General Public License version 3 or later. See
|
-# licensed under the Affero General Public License version 3 or later. See
|
||||||
-# the COPYRIGHT file.
|
-# 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
|
%p
|
||||||
= label_tag "comment_text_on_#{post_id}", t('.comment')
|
= 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}"
|
= 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
|
it 'responds to format js' do
|
||||||
post :create, comment_hash.merge(:format => 'js')
|
post :create, comment_hash.merge(:format => 'js')
|
||||||
response.code.should == '201'
|
response.code.should == '201'
|
||||||
|
response.body.should match comment_hash[:text]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue