Skip to content

Dealing With Controllers with no model

richlewis14 edited this page Nov 8, 2012 · 3 revisions

A "resource" is the "thing" that your controller is responsible for listing, creating, updating, etc. It often is a model, but need not be (e.g. you might have a "search results" resource that doesn't have a corresponding model).

If your controller really isn't dealing with a resource, then you may want to just use authorize! as appropriate within the controller, but if the controller is dealing with a resource but there is no corresponding model then you may want to use authorize_resource and specify that there is no corresponding class. This lets you "pretend" that you have a resource (i.e. you can specify abilities based on actions on a resource) without actually having a model that represents that resource.

So in your controller

 class SearchController < ApplicationController
 authorize!

Don’t forget to restart the server :)