Assume that the following roles exist in the system: developer
hacker
designer
startup
# app/models/ability.rb
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
if user.id.present?
self.merge Abilities::LoginedUserAbility.new(user)
self.merge Abilities.const_get("#{user.role}_ability".classify).new(user) if user.role.present?
else
self.merge Abilities::GuestAbility.new
end
end
end
# app/models/abilities/logined_user_ability.rb
module Abilities
class LoginedUserAbility
include CanCan::Ability
def initialize(user)
# ...
end
end
end
# app/models/abilities/developer_ability.rb
module Abilities
class DeveloperAbility
include CanCan::Ability
def initialize(user)
# ...
end
end
end
Hey bro, nice article.
you from korea ?
Congratulations @borisding1994! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!