To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / comments_controller.rb @ 912:5e80956cc792
History | View | Annotate | Download (1.05 KB)
| 1 | 22:40f7cfd4df19 | chris | 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 | 909:cbb26bc654de | Chris | |
| 16 | 22:40f7cfd4df19 | chris | 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 | 909:cbb26bc654de | Chris | |
| 36 | 22:40f7cfd4df19 | chris | end |