updating readme for 1.5
This commit is contained in:
parent
e49190fc21
commit
120eafeabd
35
README.rdoc
35
README.rdoc
|
@ -22,25 +22,15 @@ Alternatively, you can install it as a plugin.
|
||||||
|
|
||||||
== Getting Started
|
== Getting Started
|
||||||
|
|
||||||
CanCan expects a +current_user+ method to exist in controllers. If you have not already, set up some authentication (such as Authlogic[https://github.com/binarylogic/authlogic] or Devise[https://github.com/plataformatec/devise]). See {Changing Defaults}[https://github.com/ryanb/cancan/wiki/changing-defaults] if you need different behavior.
|
CanCan expects a +current_user+ method to exist in controllers. First, set up some authentication (such as Authlogic[https://github.com/binarylogic/authlogic] or Devise[https://github.com/plataformatec/devise]). See {Changing Defaults}[https://github.com/ryanb/cancan/wiki/changing-defaults] if you need to customize this behavior.
|
||||||
|
|
||||||
Next create a class called +Ability+ in "models/ability.rb" or anywhere else in the load path. It should look similar to this.
|
Next, make an +Ability+ class. CanCan 1.5 includes a generator for this.
|
||||||
|
|
||||||
class Ability
|
rails g cancan:ability
|
||||||
include CanCan::Ability
|
|
||||||
|
|
||||||
def initialize(user)
|
This is where the user permission will be defined. See the comments in models/ability.rb and {Defining Abilities}[https://github.com/ryanb/cancan/wiki/defining-abilities] for details.
|
||||||
if user.admin?
|
|
||||||
can :manage, :all
|
|
||||||
else
|
|
||||||
can :read, :all
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
The +current_user+ is passed in to this method which is where the abilities are defined. See {Defining Abilities}[https://github.com/ryanb/cancan/wiki/defining-abilities] for what can go here.
|
The current user's permissions can then be checked using the <tt>can?</tt> and <tt>cannot?</tt> methods in the view and controller.
|
||||||
|
|
||||||
The current user's permissions can then be accessed using the "can?" and "cannot?" methods in the view and controller.
|
|
||||||
|
|
||||||
<% if can? :update, @article %>
|
<% if can? :update, @article %>
|
||||||
<%= link_to "Edit", edit_article_path(@article) %>
|
<%= link_to "Edit", edit_article_path(@article) %>
|
||||||
|
@ -65,7 +55,7 @@ Setting this for every action can be tedious, therefore the +load_and_authorize_
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
See {Authorizing Controller Actions}[https://github.com/ryanb/cancan/wiki/authorizing-controller-actions] for more information
|
See {Authorizing Controller Actions}[https://github.com/ryanb/cancan/wiki/authorizing-controller-actions] for more information.
|
||||||
|
|
||||||
If the user authorization fails, a <tt>CanCan::AccessDenied</tt> exception will be raised. You can catch this and modify its behavior in the +ApplicationController+.
|
If the user authorization fails, a <tt>CanCan::AccessDenied</tt> exception will be raised. You can catch this and modify its behavior in the +ApplicationController+.
|
||||||
|
|
||||||
|
@ -79,13 +69,14 @@ If the user authorization fails, a <tt>CanCan::AccessDenied</tt> exception will
|
||||||
See {Exception Handling}[https://github.com/ryanb/cancan/wiki/exception-handling] for more information.
|
See {Exception Handling}[https://github.com/ryanb/cancan/wiki/exception-handling] for more information.
|
||||||
|
|
||||||
|
|
||||||
== Additional Docs
|
== Wiki Docs
|
||||||
|
|
||||||
* {Upgrading to 1.4}[https://github.com/ryanb/cancan/wiki/Upgrading-to-1.4]
|
* {Upgrading to 1.5}[https://github.com/ryanb/cancan/wiki/Upgrading-to-1.5]
|
||||||
* {Nested Resources}[https://github.com/ryanb/cancan/wiki/nested-resources]
|
* {Defining Abilities}[https://github.com/ryanb/cancan/wiki/Defining-Abilities]
|
||||||
* {Testing Abilities}[https://github.com/ryanb/cancan/wiki/testing-abilities]
|
* {Checking Abilities}[https://github.com/ryanb/cancan/wiki/Checking-Abilities]
|
||||||
* {Accessing Request Data}[https://github.com/ryanb/cancan/wiki/accessing-request-data]
|
* {Authorizing Controller Actions}[https://github.com/ryanb/cancan/wiki/Authorizing-Controller-Actions]
|
||||||
* {Admin Namespace}[https://github.com/ryanb/cancan/wiki/admin-namespace]
|
* {Exception Handling}[https://github.com/ryanb/cancan/wiki/Exception-Handling]
|
||||||
|
* {Changing Defaults}[https://github.com/ryanb/cancan/wiki/Changing-Defaults]
|
||||||
* {See more}[https://github.com/ryanb/cancan/wiki]
|
* {See more}[https://github.com/ryanb/cancan/wiki]
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user