Do souboru config/environment.rb přidáme:
Rails::Initializer.run do |config|
…
config.gem "declarative_authorization", :source => "http://gemcutter.org"
…Gem nainstauljeme. Tady opět používám uživatelskou instalaci.
$ rake gems:installPoté si vytvoříme konfigurační soubor config/authorization_rules.rb.
authorization do
role :admin do
has_permission_on [:articles,:comments], :to => [:index, :show, :new, :create, :edit, :update, :destroy]
end
endV modelu pak nastavíme
class User < ActiveRecord::Base
act_as_authentic
has_many :articles
has_many :comments
…
has_many :roles, :through => :assignments
def role_symbols
roles.map do |role|
rols.name.underscore.to_sym
end
end
endTo be done.
