To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / comments_controller.rb @ 1354:fc0fecf09eb9

History | View | Annotate | Download (1.69 KB)

1
# Redmine - project management software
2
# Copyright (C) 2006-2012  Jean-Philippe Lang
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
class CommentsController < ApplicationController
19
  default_search_scope :news
20
  model_object News
21
  before_filter :find_model_object
22
  before_filter :find_project_from_association
23
  before_filter :authorize
24

    
25
  def create
26
    raise Unauthorized unless @news.commentable?
27

    
28
    @comment = Comment.new
29
    @comment.safe_attributes = params[:comment]
30
    @comment.author = User.current
31
    if @news.comments << @comment
32
      flash[:notice] = l(:label_comment_added)
33
    end
34

    
35
    redirect_to :controller => 'news', :action => 'show', :id => @news
36
  end
37

    
38
  def destroy
39
    @news.comments.find(params[:comment_id]).destroy
40
    redirect_to :controller => 'news', :action => 'show', :id => @news
41
  end
42

    
43
  private
44

    
45
  # ApplicationController's find_model_object sets it based on the controller
46
  # name so it needs to be overriden and set to @news instead
47
  def find_model_object
48
    super
49
    @news = @object
50
    @comment = nil
51
    @news
52
  end
53
end