fixing spacing issues in README
This commit is contained in:
parent
52649a8da1
commit
072cb0f2de
24
README.rdoc
24
README.rdoc
|
@ -195,12 +195,12 @@ For example, let's assume that each user has_many :permissions, and each permiss
|
||||||
An alternatie approach is to define a separate "can" ability for each permission.
|
An alternatie approach is to define a separate "can" ability for each permission.
|
||||||
|
|
||||||
def initialize(user)
|
def initialize(user)
|
||||||
user.permissions.each do |permission|
|
user.permissions.each do |permission|
|
||||||
can permission.action, permission.object_type.constantize do |object|
|
can permission.action, permission.object_type.constantize do |object|
|
||||||
object.nil? || permission.object_id.nil? || permission.object_id == object.id
|
object.nil? || permission.object_id.nil? || permission.object_id == object.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
The actual details will depend largely on your application requirements, but hopefully you can see how it's possible to define permissions in the database and use them with CanCan.
|
The actual details will depend largely on your application requirements, but hopefully you can see how it's possible to define permissions in the database and use them with CanCan.
|
||||||
|
|
||||||
|
@ -209,12 +209,12 @@ The actual details will depend largely on your application requirements, but hop
|
||||||
|
|
||||||
It is very easy to test the Ability model since you can call "can?" directly on it as you would in the view or controller.
|
It is very easy to test the Ability model since you can call "can?" directly on it as you would in the view or controller.
|
||||||
|
|
||||||
def test "user can only destroy projects which he owns"
|
def test "user can only destroy projects which he owns"
|
||||||
user = User.new
|
user = User.new
|
||||||
ability = Ability.new(user)
|
ability = Ability.new(user)
|
||||||
assert ability.can?(:destroy, Project.new(:user => user))
|
assert ability.can?(:destroy, Project.new(:user => user))
|
||||||
assert ability.cannot?(:destroy, Project.new)
|
assert ability.cannot?(:destroy, Project.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
== Special Thanks
|
== Special Thanks
|
||||||
|
|
Loading…
Reference in New Issue
Block a user