Skip to content
Extraits de code Groupes Projets
Valider ec01e2c0 rédigé par maxwell's avatar maxwell
Parcourir les fichiers

Comments now working, but no AJAX, need to refresh to see them

parent faa5d216
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
class CommentsController < ApplicationController
before_filter :authenticate_user!
def create
target = Post.first(:id => params[:comment][:post_id])
text = params[:comment][:text]
if current_user.comment text, :on => target
render :text => "Woo!"
else
render :text => "Boo!"
end
end
end
\ No newline at end of file
module CommentsHelper
def target
end
def text
params[:comment][:text]
end
end
class Comment
include MongoMapper::Document
include ROXML
xml_accessor :text
key :text, String
key :target, String
timestamps!
key :post_id, ObjectId
belongs_to :post, :class_name => "Post"
key :person_id, ObjectId
belongs_to :person, :class_name => "Person"
def ==(other)
(self.message == other.message) && (self.person.email == other.person.email)
end
end
......@@ -8,6 +8,10 @@ class Post
key :person_id, ObjectId
belongs_to :person, :class_name => 'Person'
many :comments, :class_name => 'Comment', :foreign_key => :post_id
timestamps!
......
......@@ -8,8 +8,14 @@ class User < Person
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
before_validation :do_bad_things
def comment(text, options = {})
raise "Comment on what, motherfucker?" unless options[:on]
Comment.new(:person_id => self.id, :text => text, :post => options[:on]).save
end
before_validation :do_bad_things
def do_bad_things
self.password_confirmation = self.password
end
......
%li.comment
= comment.text
\---
= comment.person.real_name
\ No newline at end of file
= form_for Comment.new, :remote => true do |f|
= f.error_messages
%p
/= f.label :message
= f.text_field :text, :value => "dislike!"
= f.hidden_field :post_id, :value => post.id
= f.submit 'comment', :class => 'button'
\ No newline at end of file
......@@ -4,6 +4,12 @@
= post.message
%div.time
= link_to "#{time_ago_in_words(post.updated_at)} ago", status_message_path(post)
%div.comments
= render "comments/new_comment", :post => post
%ul.comment_set
- for comment in post.comments
= render "comments/comment", :comment => comment
- if mine?(post)
= link_to 'Destroy', status_message_path(post), :confirm => 'Are you sure?', :method => :delete
......
......@@ -3,6 +3,9 @@ Diaspora::Application.routes.draw do |map|
resources :bookmarks
resources :friends
resources :status_messages
resources :comments
#routes for devise, not really sure you will need to mess with this in the future, lets put default,
#non mutable stuff in anohter file
......
require 'spec_helper'
describe Comment do
describe "user" do
before do
@user = Factory.create :user
end
it "should be able to comment on his own status" do
status = Factory.create(:status_message, :person => @user)
status.comments.should == []
@user.comment "Yeah, it was great", :on => status
StatusMessage.first.comments.first.text.should == "Yeah, it was great"
end
it "should be able to comment on a friend's status" do
friend = Factory.create :friend
status = Factory.create(:status_message, :person => @friend)
@user.comment "sup dog", :on => status
StatusMessage.first.comments.first.text.should == "sup dog"
StatusMessage.first.comments.first.person.should == @user
end
end
end
\ No newline at end of file
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter