Skip to content

Commit

Permalink
Add info on namespaced controllers to README (#339)
Browse files Browse the repository at this point in the history
I think the Api namespace is definitely common enough to warrant its own
little example? I wished I could have found this here instead of having
to look through a lot of issue threads to finally understand this!
Especially the model_name part on a namespace controller.

Co-authored-by: Tute Costa <tutecosta@gmail.com>
  • Loading branch information
Xqua and tute committed May 6, 2020
1 parent cadecc5 commit c8c792c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ grant_on ['users#create', 'users#update'], badge: 'autobiographer', temporary: t
end
```

If your controller is under a namespace other than root (example:
`Api::ModelController`) then for merit to find your object automatically you
must specify the model class and not forget that your action is of the form
`namespace/models#action`.

See an example of a `Post` model that belongs to user:

```ruby
grant_on 'api/posts#create', badge: 'first-post', model_name: 'Post', to: :user do |post|
post.user.posts.count >= 1
end
```

## Other Actions

```ruby
Expand Down

0 comments on commit c8c792c

Please sign in to comment.