Chris@909: class CommentsController < ApplicationController Chris@909: default_search_scope :news Chris@909: model_object News Chris@909: before_filter :find_model_object Chris@909: before_filter :find_project_from_association Chris@909: before_filter :authorize Chris@909: Chris@909: verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed } Chris@909: def create Chris@909: @comment = Comment.new(params[:comment]) Chris@909: @comment.author = User.current Chris@909: if @news.comments << @comment Chris@909: flash[:notice] = l(:label_comment_added) Chris@909: end Chris@909: Chris@909: redirect_to :controller => 'news', :action => 'show', :id => @news Chris@909: end Chris@909: Chris@909: verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed } Chris@909: def destroy Chris@909: @news.comments.find(params[:comment_id]).destroy Chris@909: redirect_to :controller => 'news', :action => 'show', :id => @news Chris@909: end Chris@909: Chris@909: private Chris@909: Chris@909: # ApplicationController's find_model_object sets it based on the controller Chris@909: # name so it needs to be overriden and set to @news instead Chris@909: def find_model_object Chris@909: super Chris@909: @news = @object Chris@909: @comment = nil Chris@909: @news Chris@909: end Chris@909: Chris@909: end