You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

comments_controller.rb 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2012 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class CommentsController < ApplicationController
  18. default_search_scope :news
  19. model_object News
  20. before_filter :find_model_object
  21. before_filter :find_project_from_association
  22. before_filter :authorize
  23. def create
  24. raise Unauthorized unless @news.commentable?
  25. @comment = Comment.new
  26. @comment.safe_attributes = params[:comment]
  27. @comment.author = User.current
  28. if @news.comments << @comment
  29. flash[:notice] = l(:label_comment_added)
  30. end
  31. redirect_to :controller => 'news', :action => 'show', :id => @news
  32. end
  33. def destroy
  34. @news.comments.find(params[:comment_id]).destroy
  35. redirect_to :controller => 'news', :action => 'show', :id => @news
  36. end
  37. private
  38. # ApplicationController's find_model_object sets it based on the controller
  39. # name so it needs to be overriden and set to @news instead
  40. def find_model_object
  41. super
  42. @news = @object
  43. @comment = nil
  44. @news
  45. end
  46. end