Skip to content

Improve readme based on PR 181 comments #562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,40 @@ end

This method should be used with caution. If you don't preload the roles, the `has_cached_role?` might return `false`. In the above example, it would return `false` for `@user.has_cached_role?(:member, Forum)`, because `User.with_role(:admin, Forum)` will load only the `:admin` roles.

### Scoping

user.rb
```
has_many :posts, through: :roles, source: :resource, source_type: :Post
has_many :moderated_posts, -> { where(roles: {name: :moderator}) }, through: :roles, source: :resource, source_type: :Post
```
let's you do
```
@user.posts
# => [ all the posts where the @user has a role ]
@user.moderated_posts
# => [ all the posts where the @user has a moderator ]
```
post.rb
```
has_many :users, through: :roles, class_name: 'User', source: :users
has_many :moderators, -> { where(:roles => {name: :moderator}) }, through: :roles, class_name: 'User', source: :users
```
let's you do
```
@post.users
# => [ all the users that have a role in this post ]
@post.moderators
# => [ all the users that have a moderator role in this post ]
```

## Resources

* [Wiki](https://github.com/RolifyCommunity/rolify/wiki)
* [Usage](https://github.com/RolifyCommunity/rolify/wiki/Usage): all the available commands
* [Tutorials](https://github.com/RolifyCommunity/rolify/wiki#wiki-tutorials):
* [How-To use rolify with Devise and CanCanCan](https://github.com/RolifyCommunity/rolify/wiki/Devise---CanCanCan---rolify-Tutorial)
* [Using rolify with Devise and Authority](https://github.com/RolifyCommunity/rolify/wiki/Using-rolify-with-Devise-and-Authority)
* [Step-by-step tutorial](http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html) provided by [RailsApps](http://railsapps.github.com/)

## Upgrade from previous versions

Expand Down