Skip to content

Overriding the CommentsController

Draiken edited this page Jul 17, 2012 · 1 revision

If you need some custom behaviour on the comments controller, you can easily override Opinio's controller

First, create your own class inheriting from the engine's controller

class MyCommentsController < Opinio::CommentsController
  def create
    authorize! :create, Comment
    super
  end
end

Now we just need to redirect the default routes to your new controller, and that is done by changing the routes.rb with this:

opinio_model :controller => 'my_comments'

Inside the controller, you have access to a few internal helpers of opinio:

  • resource the object that is getting commented
  • resource_name

Good overriding :)

Clone this wiki locally