2011-10-29 16:19:11 +04:00
|
|
|
#-- encoding: UTF-8
|
2011-05-30 00:11:52 +04:00
|
|
|
#-- copyright
|
|
|
|
# ChiliProject is a project management system.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2013-01-07 02:52:16 +04:00
|
|
|
# Copyright (C) 2010-2013 the ChiliProject Team
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2011-05-30 22:52:25 +04:00
|
|
|
#
|
2011-05-30 00:11:52 +04:00
|
|
|
# See doc/COPYRIGHT.rdoc for more details.
|
|
|
|
#++
|
|
|
|
|
2010-09-22 20:25:09 +04:00
|
|
|
class CommentsController < ApplicationController
|
|
|
|
default_search_scope :news
|
|
|
|
model_object News
|
|
|
|
before_filter :find_model_object
|
|
|
|
before_filter :find_project_from_association
|
|
|
|
before_filter :authorize
|
|
|
|
|
|
|
|
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
|
|
|
def create
|
|
|
|
@comment = Comment.new(params[:comment])
|
|
|
|
@comment.author = User.current
|
|
|
|
if @news.comments << @comment
|
|
|
|
flash[:notice] = l(:label_comment_added)
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-22 20:25:09 +04:00
|
|
|
redirect_to :controller => 'news', :action => 'show', :id => @news
|
|
|
|
end
|
|
|
|
|
2010-09-23 19:20:19 +04:00
|
|
|
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
|
|
|
|
def destroy
|
|
|
|
@news.comments.find(params[:comment_id]).destroy
|
|
|
|
redirect_to :controller => 'news', :action => 'show', :id => @news
|
|
|
|
end
|
|
|
|
|
2010-09-22 20:25:09 +04:00
|
|
|
private
|
|
|
|
|
|
|
|
# ApplicationController's find_model_object sets it based on the controller
|
|
|
|
# name so it needs to be overriden and set to @news instead
|
|
|
|
def find_model_object
|
|
|
|
super
|
|
|
|
@news = @object
|
|
|
|
@comment = nil
|
|
|
|
@news
|
|
|
|
end
|
2011-05-30 22:52:25 +04:00
|
|
|
|
2010-09-22 20:25:09 +04:00
|
|
|
end
|