comparison app/controllers/comments_controller.rb @ 22:40f7cfd4df19

* Update to SVN trunk rev 4173
author Chris Cannam <chris.cannam@soundsoftware.ac.uk>
date Fri, 24 Sep 2010 14:06:04 +0100
parents
children cbb26bc654de
comparison
equal deleted inserted replaced
14:1d32c0a0efbf 22:40f7cfd4df19
1 class CommentsController < ApplicationController
2 default_search_scope :news
3 model_object News
4 before_filter :find_model_object
5 before_filter :find_project_from_association
6 before_filter :authorize
7
8 verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
9 def create
10 @comment = Comment.new(params[:comment])
11 @comment.author = User.current
12 if @news.comments << @comment
13 flash[:notice] = l(:label_comment_added)
14 end
15
16 redirect_to :controller => 'news', :action => 'show', :id => @news
17 end
18
19 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
20 def destroy
21 @news.comments.find(params[:comment_id]).destroy
22 redirect_to :controller => 'news', :action => 'show', :id => @news
23 end
24
25 private
26
27 # ApplicationController's find_model_object sets it based on the controller
28 # name so it needs to be overriden and set to @news instead
29 def find_model_object
30 super
31 @news = @object
32 @comment = nil
33 @news
34 end
35
36 end