Server side of ajaxy comments done, need to modify comments/_comments and make it work.
This commit is contained in:
parent
71dbfce23f
commit
3f555eefc4
5 changed files with 37 additions and 4 deletions
|
|
@ -6,7 +6,8 @@ class CommentsController < ApplicationController
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
respond_to :html, :mobile
|
respond_to :html, :mobile, :only => [:create, :destroy]
|
||||||
|
respond_to :js, :only => [:index]
|
||||||
|
|
||||||
rescue_from ActiveRecord::RecordNotFound do
|
rescue_from ActiveRecord::RecordNotFound do
|
||||||
render :nothing => true, :status => 404
|
render :nothing => true, :status => 404
|
||||||
|
|
@ -53,4 +54,13 @@ class CommentsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def index
|
||||||
|
@post = current_user.find_visible_post_by_id(params[:post_id])
|
||||||
|
if @post
|
||||||
|
@comments = @post.comments
|
||||||
|
else
|
||||||
|
raise ActiveRecord::RecordNotFound.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,9 @@
|
||||||
-# the COPYRIGHT file.
|
-# the COPYRIGHT file.
|
||||||
|
|
||||||
- unless comments_expanded
|
- unless comments_expanded
|
||||||
%ul.show_comments{:class => ("hidden" if comments.size <= 3)}
|
%ul.show_comments{:class => ("hidden" if post.comments.count <= 3)}
|
||||||
%li
|
%li
|
||||||
%b= comment_toggle(comments.size)
|
%b= comment_toggle( post.comments.count )
|
||||||
|
|
||||||
%ul.comments{:id => post.id, :class => ("hidden" if comments.size == 0 && !comments_expanded)}
|
%ul.comments{:id => post.id, :class => ("hidden" if comments.size == 0 && !comments_expanded)}
|
||||||
-if comments.size > 3
|
-if comments.size > 3
|
||||||
|
|
|
||||||
2
app/views/comments/index.js.erb
Normal file
2
app/views/comments/index.js.erb
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
var html = <%= render :partial => 'comments/comment', :collection => @comments, :locals => {:post => @post} %>
|
||||||
|
$('.comments', '.stream_element[data-guid="<%= @post.id %>"]').html(html);
|
||||||
|
|
@ -16,7 +16,7 @@ Diaspora::Application.routes.draw do
|
||||||
|
|
||||||
resources :posts, :only => [:show, :destroy] do
|
resources :posts, :only => [:show, :destroy] do
|
||||||
resources :likes, :only => [:create, :destroy, :index]
|
resources :likes, :only => [:create, :destroy, :index]
|
||||||
resources :comments, :only => [:create, :destroy]
|
resources :comments, :only => [:create, :destroy, :index]
|
||||||
end
|
end
|
||||||
|
|
||||||
get 'bookmarklet' => 'status_messages#bookmarklet'
|
get 'bookmarklet' => 'status_messages#bookmarklet'
|
||||||
|
|
|
||||||
|
|
@ -117,4 +117,25 @@ describe CommentsController do
|
||||||
response.body.strip.should be_empty
|
response.body.strip.should be_empty
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#index' do
|
||||||
|
before do
|
||||||
|
@message = bob.post(:status_message, :text => "hey", :to => bob.aspects.first.id)
|
||||||
|
@comments = [alice, bob, eve].map{ |u| u.comment("hey", :post => @message) }
|
||||||
|
end
|
||||||
|
it 'returns all the comments for a post' do
|
||||||
|
get :index, :post_id => @message.id, :format => 'js'
|
||||||
|
assigns[:comments].should == @comments
|
||||||
|
end
|
||||||
|
it 'returns a 404 on a nonexistent post' do
|
||||||
|
get :index, :post_id => 235236, :format => 'js'
|
||||||
|
response.status.should == 404
|
||||||
|
end
|
||||||
|
it 'returns a 404 on a post that is not visible to the signed in user' do
|
||||||
|
message = eve.post(:status_message, :text => "hey", :to => eve.aspects.first.id)
|
||||||
|
bob.comment("hey", :post => @message)
|
||||||
|
get :index, :post_id => message.id, :format => 'js'
|
||||||
|
response.status.should == 404
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue