To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / comments_controller.rb @ 1040:ff783f2cc500

History | View | Annotate | Download (1.08 KB)

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
11
    @comment.safe_attributes = params[:comment]
12
    @comment.author = User.current
13
    if @news.comments << @comment
14
      flash[:notice] = l(:label_comment_added)
15
    end
16

    
17
    redirect_to :controller => 'news', :action => 'show', :id => @news
18
  end
19

    
20
  verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
21
  def destroy
22
    @news.comments.find(params[:comment_id]).destroy
23
    redirect_to :controller => 'news', :action => 'show', :id => @news
24
  end
25

    
26
  private
27

    
28
  # ApplicationController's find_model_object sets it based on the controller
29
  # name so it needs to be overriden and set to @news instead
30
  def find_model_object
31
    super
32
    @news = @object
33
    @comment = nil
34
    @news
35
  end
36

    
37
end