README.md in petergate-1.7.0 vs README.md in petergate-1.7.1

- old
+ new

@@ -10,11 +10,11 @@ > > -- <cite>1 Peter 3:41</cite> Installation ------ -#####Get the gem +##### Get the gem Add this line to your application's Gemfile: gem 'petergate' And then execute: @@ -22,12 +22,13 @@ bundle Or install it yourself as: gem install petergate -#####Prerequisites: Setup Authentication (Devise) +##### Prerequisites: Setup Authentication (Devise) + Make sure your user model is defined in app/models/user.rb and called User. If you're using [devise](https://github.com/plataformatec/devise) you're in luck, otherwise you'll have to add following methods to your project: @@ -35,31 +36,31 @@ user_signed_in? current_user after_sign_in_path_for(current_user) authenticate_user! -#####Run the generators +##### Run the generators rails g petergate:install rake db:migrate - -This will add a migration and insert petergate into your User model. - + +This will add a migration and insert petergate into your User model. + Usage ------ -####User Model +#### User Model Configure available roles by modifying this block at the top of your user.rb. ```ruby ############################################################################################ ## PeterGate Roles ## ## The :user role is added by default and shouldn't be included in this list. ## ## The :root_admin can access any page regardless of access settings. Use with caution! ## ## The multiple option can be set to true if you need users to have multiple roles. ## petergate(roles: [:admin, :editor], multiple: false) ## -############################################################################################ +############################################################################################ ``` ##### Instance Methods ```ruby @@ -69,14 +70,14 @@ user.available_roles => [:admin, :editor] user.has_roles?(:admin, :editors) # returns true if user is any of roles passed in as params. ``` ##### Class Methods -`User.role_editors => #list of editors. Method is created for all roles. role_admins, role_teachers, etc.` +`User.#{role}_editors => #list of editors. Method is created for all roles. Roles [admin, :teacher] will have corresponding methods role_admins, role_teachers, etc.` -####Controllers - +#### Controllers + Setup permissions in your controllers the same as you would for a before filter like so: ```ruby access all: [:show, :index], user: {except: [:destroy]}, company_admin: :all @@ -101,10 +102,18 @@ def roles=(v) self[:roles] = v.map(&:to_sym).to_a.select{|r| r.size > 0 && ROLES.include?(r)} end ``` +If you need to deny access you can use the forbidden! method: +```ruby +before_action :check_active_user + +def check_active_user + forbidden! unless current_user.active +end +``` If you want to change the `permission denied` message you can add to the access line: ```ruby access user: [:show, :index], message: "You shall not pass" ```