Skip to content

Commit c821790

Browse files
committed
update README
1 parent c5d7fc6 commit c821790

File tree

1 file changed

+115
-18
lines changed

1 file changed

+115
-18
lines changed

README.md

Lines changed: 115 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
# Activeadmin::Nested::Namespaces
1+
# ActiveAdmin Nested Namespace
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/activeadmin/nested/namespaces`. To experiment with that code, run `bin/console` for an interactive prompt.
4-
5-
TODO: Delete this and the text above, and describe your gem
3+
This plugin allows you to register resources/pages with nested namespaces in ActiveAdmin.
64

75
## Installation
86

@@ -14,30 +12,129 @@ gem 'activeadmin-nested-namespaces'
1412

1513
And then execute:
1614

17-
$ bundle
15+
$ bundle install
1816

19-
Or install it yourself as:
2017

21-
$ gem install activeadmin-nested-namespaces
18+
Copy and paste these lines to `config/initializers/active_admin_nested_namespace.rb`
2219

23-
## Usage
20+
```ruby
21+
require 'active_admin/nested_namespace'
2422

25-
TODO: Write usage instructions here
23+
if defined?(ActiveAdmin::NestedNamespace)
24+
ActiveAdmin::NestedNamespace.setup
25+
end
26+
```
2627

27-
## Development
2828

29-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
29+
# Get Started
3030

31-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
31+
Register resources to 2 different namespaces:
3232

33-
## Contributing
33+
```ruby
34+
# /app/admin/site1/foo/bar/posts.rb
35+
ActiveAdmin.register Post, namespace: [:admin, :site1, :foo, :bar] do
36+
...
37+
end
38+
```
3439

35-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activeadmin-nested-namespaces. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
40+
```ruby
41+
# /app/admin/site2/demo/posts.rb
42+
ActiveAdmin.register Post, namespace: [:admin, :site2, :demo] do
43+
...
44+
end
45+
```
3646

37-
## License
47+
It will generate routes like:
3848

39-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
49+
```
50+
admin_site1_foo_bar_root GET /admin/site1/foo/bar(.:format) admin/site1/foo/bar/dashboard#index
51+
admin_site2_demo_root GET /admin/site2/demo(.:format)
52+
batch_action_admin_site1_foo_bar_posts POST /admin/site1/foo/bar/posts/batch_action(.:format) admin/site1/foo/bar/posts#batch_action
53+
admin_site1_foo_bar_posts GET /admin/site1/foo/bar/posts(.:format) admin/site1/foo/bar/posts#index
54+
POST /admin/site1/foo/bar/posts(.:format) admin/site1/foo/bar/posts#create
55+
new_admin_site1_foo_bar_post GET /admin/site1/foo/bar/posts/new(.:format) admin/site1/foo/bar/posts#new
56+
edit_admin_site1_foo_bar_post GET /admin/site1/foo/bar/posts/:id/edit(.:format) admin/site1/foo/bar/posts#edit
57+
admin_site1_foo_bar_post GET /admin/site1/foo/bar/posts/:id(.:format) admin/site1/foo/bar/posts#show
58+
PATCH /admin/site1/foo/bar/posts/:id(.:format) admin/site1/foo/bar/posts#update
59+
PUT /admin/site1/foo/bar/posts/:id(.:format) admin/site1/foo/bar/posts#update
60+
DELETE /admin/site1/foo/bar/posts/:id(.:format) admin/site1/foo/bar/posts#destroy
61+
admin_site1_foo_bar_comments GET /admin/site1/foo/bar/comments(.:format) admin/site1/foo/bar/comments#index
62+
POST /admin/site1/foo/bar/comments(.:format) admin/site1/foo/bar/comments#create
63+
admin_site1_foo_bar_comment GET /admin/site1/foo/bar/comments/:id(.:format) admin/site1/foo/bar/comments#show
64+
DELETE /admin/site1/foo/bar/comments/:id(.:format) admin/site1/foo/bar/comments#destroy
65+
batch_action_admin_site2_demo_posts POST /admin/site2/demo/posts/batch_action(.:format) admin/site2/demo/posts#batch_action
66+
admin_site2_demo_posts GET /admin/site2/demo/posts(.:format) admin/site2/demo/posts#index
67+
edit_admin_site2_demo_post GET /admin/site2/demo/posts/:id/edit(.:format) admin/site2/demo/posts#edit
68+
admin_site2_demo_post GET /admin/site2/demo/posts/:id(.:format) admin/site2/demo/posts#show
69+
PATCH /admin/site2/demo/posts/:id(.:format) admin/site2/demo/posts#update
70+
PUT /admin/site2/demo/posts/:id(.:format) admin/site2/demo/posts#update
71+
admin_site2_demo_comments GET /admin/site2/demo/comments(.:format) admin/site2/demo/comments#index
72+
POST /admin/site2/demo/comments(.:format) admin/site2/demo/comments#create
73+
admin_site2_demo_comment GET /admin/site2/demo/comments/:id(.:format) admin/site2/demo/comments#show
74+
DELETE /admin/site2/demo/comments/:id(.:format) admin/site2/demo/comments#destroy
4075
41-
## Code of Conduct
76+
```
77+
78+
# Configuration
79+
80+
In your initializers/active_admin.rb, you can define your own handler to the following methods.
81+
82+
* authentication_method
83+
* current_user_method
84+
* logout_link_path
85+
86+
For example:
87+
88+
``` ruby
89+
# config.authentication_method = :authenticate_admin_user!
90+
config.authentication_method = Proc.new do |name_path|
91+
if [config.default_namespace, :root].include?(name_path.first)
92+
:authenticate_admin_user!
93+
else
94+
"authenticate_#{name_path.map(&:to_s).join('_').underscore}_admin_user!".to_sym
95+
end
96+
end
97+
98+
# config.current_user_method = :current_admin_user
99+
config.current_user_method = Proc.new do |name_path|
100+
if [config.default_namespace, :root].include?(name_path.first)
101+
:current_admin_user
102+
else
103+
"current_#{name_path.map(&:to_s).join('_').underscore}_admin_user".to_sym
104+
end
105+
end
106+
107+
# config.logout_link_path = :destroy_admin_user_session_path
108+
config.logout_link_path = Proc.new do |name_path|
109+
if [config.default_namespace, :root].include?(name_path.first)
110+
:destroy_admin_user_session_path
111+
else
112+
"destroy_#{name_path.map(&:to_s).join('_').underscore}_admin_user_session_path".to_sym
113+
end
114+
end
115+
116+
```
117+
118+
And in your routes.rb:
119+
120+
```ruby
121+
namespace :site1 do
122+
namespace :foo do
123+
namespace :bar do
124+
devise_for :admin_users, ActiveAdmin::Devise.config
125+
end
126+
end
127+
end
128+
namespace :site2 do
129+
namespace :demo do
130+
devise_for :admin_users, ActiveAdmin::Devise.config
131+
end
132+
end
133+
```
134+
135+
## Contributors
136+
[Martin Chan](https://twitter.com/osiutino) - creator
137+
138+
## License
42139

43-
Everyone interacting in the Activeadmin::Nested::Namespaces project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/activeadmin-nested-namespaces/blob/master/CODE_OF_CONDUCT.md).
140+
[MIT](https://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)