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 @ 437:102056ec2de9

History | View | Annotate | Download (1.06 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(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