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