Mercurial > hg > soundsoftware-site
annotate app/controllers/comments_controller.rb @ 1022:f2ec92061fca browsing
Merge from live branch
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Tue, 13 Nov 2012 10:35:40 +0000 |
parents | 5f33065ddc4b |
children | 433d4f72a19b |
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@929 | 10 @comment = Comment.new |
Chris@929 | 11 @comment.safe_attributes = params[:comment] |
chris@22 | 12 @comment.author = User.current |
chris@22 | 13 if @news.comments << @comment |
chris@22 | 14 flash[:notice] = l(:label_comment_added) |
chris@22 | 15 end |
Chris@909 | 16 |
chris@22 | 17 redirect_to :controller => 'news', :action => 'show', :id => @news |
chris@22 | 18 end |
chris@22 | 19 |
chris@22 | 20 verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } |
chris@22 | 21 def destroy |
chris@22 | 22 @news.comments.find(params[:comment_id]).destroy |
chris@22 | 23 redirect_to :controller => 'news', :action => 'show', :id => @news |
chris@22 | 24 end |
chris@22 | 25 |
chris@22 | 26 private |
chris@22 | 27 |
chris@22 | 28 # ApplicationController's find_model_object sets it based on the controller |
chris@22 | 29 # name so it needs to be overriden and set to @news instead |
chris@22 | 30 def find_model_object |
chris@22 | 31 super |
chris@22 | 32 @news = @object |
chris@22 | 33 @comment = nil |
chris@22 | 34 @news |
chris@22 | 35 end |
Chris@909 | 36 |
chris@22 | 37 end |