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 @ 1298:4f746d8966dd

History | View | Annotate | Download (1.62 KB)

1 1115:433d4f72a19b Chris
# Redmine - project management software
2 1295:622f24f53b42 Chris
# Copyright (C) 2006-2013  Jean-Philippe Lang
3 1115:433d4f72a19b Chris
#
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 22:40f7cfd4df19 chris
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 1115:433d4f72a19b Chris
    raise Unauthorized unless @news.commentable?
27
28 929:5f33065ddc4b Chris
    @comment = Comment.new
29
    @comment.safe_attributes = params[:comment]
30 22:40f7cfd4df19 chris
    @comment.author = User.current
31
    if @news.comments << @comment
32
      flash[:notice] = l(:label_comment_added)
33
    end
34 909:cbb26bc654de Chris
35 1295:622f24f53b42 Chris
    redirect_to news_path(@news)
36 22:40f7cfd4df19 chris
  end
37
38
  def destroy
39
    @news.comments.find(params[:comment_id]).destroy
40 1295:622f24f53b42 Chris
    redirect_to news_path(@news)
41 22:40f7cfd4df19 chris
  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