A simple users system 2/2
Now that we have a user model and now that Access Control System is updated according to it, we can use it correctly in our controllers and view as usual. If you administrate a part of your application using Active Scaffold, you may edit your controllers as follows:
class CustomerAccountsController < ActionController
active_scaffold
end
class CustomersController < ActionController
access_control :DEFAULT => “admin | reseller”,
[:create, :update, :destroy] => “reseller”
active_scaffold :customers do |config|
config.columns = [:login, :email, :first_name, :last_name, :password, :password_confirmation, :customer_account]
list.columns.exclude :password, :password_confirmation
end
def authorize_create?
permit?(“reseller”)
end
def authorize_update?
permit?(“reseller”)
end
def authorize_delete?
permit?(“reseller”)
end
end
The authorize methods are used by Active Scaffold in views: the links to create, update or delete are not shown when these methods return false. That's it !