Redmine Refactor #120: Move Method from NewsController to CommentsController

Since I created the CommentsController yesterday, today I’m going to move the #destroy_comment method over to it. I also threw in a bit of rename method magic to make it match the RESTful naming conventions.

Before

1
2
3
class NewsController  'show', :id => @news
  end
end
1
2
3
class CommentsController < ApplicationController
  # ...
end

After

1
2
3
class NewsController < ApplicationController
  # No more destroy_comment
end
1
2
3
4
5
6
class CommentsController  :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
  def destroy
    @news.comments.find(params[:comment_id]).destroy
    redirect_to :controller => 'news', :action => 'show', :id => @news
  end
end

With this refactoring, the NewsController is looking really good. There is only one non-standard method left, #preview. Since Redmine already has a controller for previewing issues, I can use move method tomorrow and complete the NewsController.

Reference commit