开发者

cancan: getting past undefined method `find' for Userhome:Class

cancan did not work with a controller that did not have a class. So I created the userhome.rb model:

class Userhome
end

There is an action in the userhome controller that accesses a page 开发者_StackOverflow中文版in another directory/class. An attempt to access it yields the following error:

undefined method `find' for Userhome:Class

Is the best thing for me to do...:

  1. delete the userhome model, and
  2. remove "load_and_authorize_resource" from the userhome controller, and
  3. just lock the application down with cancan in every other area possible?

Or is there a workaround to deal with this error?


Take a look at the CanCan documentation on non-RESTful controllers.

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 (which sounds like it may describe your situation) 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜