annotate app/controllers/comments_controller.rb @ 507:0c939c159af4
redmine-1.2
Update to Redmine 1.2.1 on 1.2-stable branch (Redmine SVN rev 6270)
author |
Chris Cannam |
date |
Thu, 14 Jul 2011 10:32:19 +0100 |
parents |
40f7cfd4df19 |
children |
cbb26bc654de |
rev |
line source |
chris@22
|
1 class CommentsController < ApplicationController
|
chris@22
|
2 default_search_scope :news
|
chris@22
|
3 model_object News
|
chris@22
|
4 before_filter :find_model_object
|
chris@22
|
5 before_filter :find_project_from_association
|
chris@22
|
6 before_filter :authorize
|
chris@22
|
7
|
chris@22
|
8 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
chris@22
|
9 def create
|
chris@22
|
10 @comment = Comment.new(params[:comment])
|
chris@22
|
11 @comment.author = User.current
|
chris@22
|
12 if @news.comments << @comment
|
chris@22
|
13 flash[:notice] = l(:label_comment_added)
|
chris@22
|
14 end
|
chris@22
|
15
|
chris@22
|
16 redirect_to :controller => 'news', :action => 'show', :id => @news
|
chris@22
|
17 end
|
chris@22
|
18
|
chris@22
|
19 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
|
chris@22
|
20 def destroy
|
chris@22
|
21 @news.comments.find(params[:comment_id]).destroy
|
chris@22
|
22 redirect_to :controller => 'news', :action => 'show', :id => @news
|
chris@22
|
23 end
|
chris@22
|
24
|
chris@22
|
25 private
|
chris@22
|
26
|
chris@22
|
27 # ApplicationController's find_model_object sets it based on the controller
|
chris@22
|
28 # name so it needs to be overriden and set to @news instead
|
chris@22
|
29 def find_model_object
|
chris@22
|
30 super
|
chris@22
|
31 @news = @object
|
chris@22
|
32 @comment = nil
|
chris@22
|
33 @news
|
chris@22
|
34 end
|
chris@22
|
35
|
chris@22
|
36 end
|