3 ms·
The CanCan ruby authorization library does a neat bit of metaprogramming. It offers a function "load_resource" which you put at the top of your controller. The
by stevepike 12y ago
The CanCan ruby authorization library does a neat bit of metaprogramming. It offers a function "load_resource" which you put at the top of your controller. The function uses the name of the controller class and the name of the currently executing controller action to automatically set a resource. It looks like this:
class CarsController < ActionController::Base
load_resource
def index
# @cars is defined
end
def show
# @car is defined
end
end