concept ability in category rails

This is an excerpt from Manning's book Rails 4 in Action: Revised Edition of Rails 3 in Action.
The attr_accessible approach caused problems because different controllers might want to make available different sets of parameters for the same model, depending on the context. For instance, an admin area of the site may want to permit different fields than the user-facing area of the site—admins might have more fields, such as the ability to set the owner of a project.
$ git add . $ git commit -m "Add the ability to view a list of all projects" $ git push
To track the states, you’ll let users leave a comment. Users will be able to leave a text comment about the ticket and may also elect to change the state of the ticket by selecting another state from a drop-down list. But not all users will be able to leave a comment and change the state—you’ll protect both creating a comment and changing the state from unauthorized access. By the time you’re done with all of this, the users of your application will have the ability to add comments to tickets. Some users, depending on their permissions, will be able to change the state of a ticket through the comment interface.
You’ll begin by creating the interface through which a user will create a comment, and then you’ll build the ability for the user to change the state of a ticket. Let’s get into it.

This is an excerpt from Manning's book Rails 3 in Action.
git add . git commit -m "Added the ability to view a list of all projects" git push
By defining this new controller as inheriting from Devise::RegistrationsController, you inherit all the behavior from that controller and gain the ability to override things such as the after_inactive_sign_up_path_for, of which you take full advantage here. The resource argument is the User object representing who’s signing up. You could use it, but in this context, don’t. Next, you need to tell Devise to use this controller instead of its own. Alter the following line in config/routes.rb
The ||= sets @current_ability if it isn’t already set. The :: before Ability indicates to Ruby that you want the Ability at the root namespace. This allows you to have a module called CanCan::Ability and a class at Ability and to differentiate between the two. In this example, it’s trying to access just Ability, which is a class that doesn’t yet exist.
This new Ability class will provide the link between users and their permissions. You define it in a new file at app/models/ability.rb exactly like the following listing.
Listing 8.8. app/models/ability.rb
class Ability include CanCan::Ability def initialize(user) user.permissions.each do |permission| can permission.action.to_sym, permission.thing_type.constantize do |thing| thing.nil? || permission.thing_id.nil? || permission.thing_id == thing.id end end end endThe Ability class’s initialize method defines how can? and cannot? will act. In this example, you iterate over all the users’ permissions and use the can? method to say that a user can perform a specific function. Users who shouldn’t be able to perform that function won’t have an entry in the permissions table for it. This is the whitelist authorization described at the beginning of the chapter.