concept role in category rails

This is an excerpt from Manning's book Rails 4 in Action: Revised Edition of Rails 3 in Action.
In this chapter, you’ll expand on authorization options by implementing a broader authorization system using a Role model. The records for this model’s table define the roles that specified users will have on specific projects in your system. Each record tracks a user who has a specific role, the project to which the role applies, and the type of role granted. You’ll create three types of roles in your system:
You haven’t yet defined the roles variable or method. What should it be? Rails expects it to be a hash, with the keys matching the display value, and the values matching the value that will be submitted to the server if that option is selected; something like the following:
{ 'Manager' => 'manager', 'Editor' => 'editor', 'Viewer' => 'viewer' }You can define a view helper method to give you this data. You’ve written a few view helpers before, for things like page titles and outputting certain HTML for admins only—now you’ll write one to generate a list of roles.
Open app/helpers/admin/application_helper.rb, and add a new method definition for roles inside the module.
Listing 8.77. A naive roles definition in Admin::ApplicationHelper
module Admin::ApplicationHelper def roles { 'Manager' => 'manager', 'Editor' => 'editor', 'Viewer' => 'viewer' } end endYou can do a bit better, though. What if you add new roles? Plus, the display names just look like the name of the role, with a capital letter. What about this instead?
Listing 8.78. An improved roles definition
module Admin::ApplicationHelper def roles hash = {} %w(manager editor viewer).each do |role| hash[role.titleize] = role end hash end endNow you only list the names of the roles once, using Ruby’s special %w() notation, which is a shortcut for generating an array of strings. Then you build up a hash in the right format by calling Rails’ titleize helper[5] on each role name. But you’re still listing out role names manually, when that information really belongs somewhere else—like in the Role model.