Skip to content

Commit ee0abe7

Browse files
committed
Move docs from wiki to the project repository itself
Moving the docs allows them to more easily be developed in a first-class manner through pull requests. The docs can stay aligned with code changes as they happen within the same commit. For example, as the code gets refactored, docs may become incorrect or out of date. With the docs in the repository, this can be caught during development and review. Contributors can provide reviewable documentaiton-only changes, even small ones, thus improving the community experience. An up to date version of the docs were cloned and copied using: git clone https://github.com/railsadminteam/rails_admin.wiki.git The docs were left as-is as much as possible. If there are desired changes, these can now be opened as future pull requests. Articles that are linked to internally are not included. Changes to the wiki articles: - All previous wiki links have been converted to be compatible with GitHub flavored Markdown so links continue to work as before. - Small formatting changes to be compliant with Prettier. - References to *.coffee files were updated to *.js. - Renamed index.md to home.md to follow conventions. - Added an H1 header to all articles which was previously implicitly added by the wiki engine. Once this change lands, the wiki can be removed so as to avoid confusion for new users.
1 parent fa0db21 commit ee0abe7

File tree

91 files changed

+5718
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+5718
-7
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RailsAdmin is a Rails engine that provides an easy-to-use interface for managing
2929

3030
[demo]: http://rails-admin-tb.herokuapp.com/
3131
[dummy_app]: https://github.com/bbenezech/dummy_app
32-
[docs]: https://github.com/railsadminteam/rails_admin/wiki
32+
[docs]: docs/index.md
3333

3434
## Features
3535

@@ -59,9 +59,9 @@ RailsAdmin is a Rails engine that provides an easy-to-use interface for managing
5959

6060
In `config/initializers/rails_admin.rb`:
6161

62-
[Details](https://github.com/railsadminteam/rails_admin/wiki/Base-configuration)
62+
[Details](docs/base-configuration.md)
6363

64-
To begin with, you may be interested in setting up [Devise](https://github.com/railsadminteam/rails_admin/wiki/Devise), [CanCanCan](https://github.com/railsadminteam/rails_admin/wiki/Cancancan) or [Papertrail](https://github.com/railsadminteam/rails_admin/wiki/Papertrail)!
64+
To begin with, you may be interested in setting up [Devise](docs/devise.md), [CanCanCan](docs/cancancan.md) or [Papertrail](docs/papertrail.md)!
6565

6666
### Per model
6767

@@ -78,14 +78,14 @@ class Ball < ActiveRecord::Base
7878
end
7979
```
8080

81-
Details: [Models](https://github.com/railsadminteam/rails_admin/wiki/Models), [Groups](https://github.com/railsadminteam/rails_admin/wiki/Groups), [Fields](https://github.com/railsadminteam/rails_admin/wiki/Fields)
81+
Details: [Models](docs/models.md), [Groups](docs/groups.md), [Fields](docs/fields.md)
8282

8383
## Support
8484

8585
If you have a question, please check this README, the wiki, and the [list of
8686
known issues][troubleshoot].
8787

88-
[troubleshoot]: https://github.com/railsadminteam/rails_admin/wiki/Troubleshoot
88+
[troubleshoot]: docs/troubleshoot.md
8989

9090
If you still have a question, you can ask the [official RailsAdmin mailing
9191
list][list].

docs/actions.md

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
## Default
2+
3+
Actions used to be static and hard-coded. A community request was that they could be added/removed/customized.
4+
5+
This is now possible.
6+
7+
By default, to keep existing installation safe, all actions are added as they used to be.
8+
9+
Default is equivalent to:
10+
11+
```ruby
12+
# config/initializers/rails_admin.rb
13+
RailsAdmin.config do |config|
14+
config.actions do
15+
# root actions
16+
dashboard # mandatory
17+
# collection actions
18+
index # mandatory
19+
new
20+
export
21+
history_index
22+
bulk_delete
23+
# member actions
24+
show
25+
edit
26+
delete
27+
history_show
28+
show_in_app
29+
end
30+
end
31+
```
32+
33+
## Use existing actions and customize them
34+
35+
Simply list them and pass an optional block, like so:
36+
37+
```ruby
38+
config.actions do
39+
dashboard do
40+
i18n_key :dash
41+
end
42+
index
43+
new
44+
end
45+
```
46+
47+
Please note that `dashboard` and `index` are mandatory for the moment, but this may change in the future.
48+
49+
## Define actions
50+
51+
- `root` defines root level actions (Dashboard, etc.)
52+
- `collection` defines collection level actions (Index, New, etc.)
53+
- `member` defines member level actions (Show, Edit, etc.)
54+
55+
First argument is the key of the action.
56+
It will be the `i18n_key`, the `route_fragment`, the `action_name`, the `authorization_key`, etc.
57+
You can override each of these individually. See the respective class and the [Base Action class](../lib/rails_admin/config/actions/base.rb) to get the list of these options.
58+
59+
Second (optional) argument is the key of the parent class. It can be any existing Action class. If none given, it will be `Base`.
60+
61+
Then you can pass the configuration block.
62+
63+
Then add `app/views/rails_admin/main/my_action.html.<erb|haml>` in your application, where you will be able to access:
64+
65+
- `@abstract_model` (except for root actions, give the RailsAdmin representation of the model. Use .model to have your ActiveRecord original model)
66+
- `@model_config` (except for root actions, give the RailsAdmin configuration of the model)
67+
- `@objects = list_entries` (for collection actions, list the entries as specified in params, see the :index action and template)
68+
- `@object` (member actions only, ActiveRecord object)
69+
70+
```ruby
71+
config.actions do
72+
root :my_dashboard, :dashboard # subclass Dashboard. Accessible at /admin/my_dashboard
73+
collection :my_collection_action do # subclass Base. Accessible at /admin/<model_name>/my_collection_action
74+
...
75+
end
76+
member :my_member_action do # subclass Base. Accessible at /admin/<model_name>/<id>/my_member_action
77+
i18n_key :edit # will have the same menu/title labels as the Edit action.
78+
end
79+
end
80+
81+
```
82+
83+
## Create a reusable action
84+
85+
```ruby
86+
# somewhere in your lib/ directory:
87+
88+
require 'rails_admin/config/actions'
89+
require 'rails_admin/config/actions/base'
90+
91+
module RailsAdmin
92+
module Config
93+
module Actions
94+
class MyAction < RailsAdmin::Config::Actions::Base
95+
RailsAdmin::Config::Actions.register(self)
96+
register_instance_option :my_option do
97+
:default_value
98+
end
99+
end
100+
end
101+
end
102+
end
103+
104+
# use it like this:
105+
106+
config.actions do
107+
my_action do
108+
my_option :another_value
109+
end
110+
end
111+
```
112+
113+
If you want to share it as a gem, see [custom action](custom-action.md).
114+
115+
## Action wording for title, menu, breadcrumb and links
116+
117+
Default I18n key is action name underscored. You can change it like so:
118+
119+
```ruby
120+
config.actions do
121+
dashboard do
122+
i18n_key :customized
123+
end
124+
...
125+
end
126+
```
127+
128+
Then head for your `config/locales/rails_admin.xx.yml` file:
129+
130+
```yaml
131+
xx:
132+
admin:
133+
actions:
134+
<customized>:
135+
title: "..."
136+
menu: "..."
137+
breadcrumb: "..."
138+
link: "..."
139+
```
140+
141+
See [rails_admin.en.yml](../config/locales/rails_admin.en.yml) to get an idea.
142+
143+
Actions can provide specific option configuration, check their respective wiki page.
144+
145+
## Controlling visibility
146+
147+
### Through authorization
148+
149+
Authorization is done automatically before any link is displayed, any page accessed, etc.
150+
Check [CanCanCan](cancancan.md) for the list of key used by RailsAdmin default actions.
151+
152+
You can change the authorization key with:
153+
154+
```ruby
155+
config.actions do
156+
dashboard do
157+
authorization_key :customized
158+
end
159+
...
160+
end
161+
```
162+
163+
### Per-model basis
164+
165+
```ruby
166+
config.actions do
167+
edit do
168+
only ['Player']
169+
end
170+
delete do
171+
except ['Team', 'Ball']
172+
end
173+
end
174+
```
175+
176+
### Visible block
177+
178+
You can use these 3 bindings to decide whereas the action should be visible or not:
179+
180+
- `bindings[:controller]` is current controller instance
181+
- `bindings[:abstract_model]` is checked abstract model (except root actions)
182+
- `bindings[:object]` is checked instance object (member actions only)
183+
184+
For instance, if you want to allow editing of games, but only if they haven't yet started:
185+
186+
```ruby
187+
config.actions do
188+
edit do
189+
visible do
190+
object = bindings[:object]
191+
case object
192+
when Game then !object.started? # only allow editing games if they haven't started
193+
when Player then true # allow editing of Players any time
194+
else false # don't allow editing anything else
195+
end
196+
end
197+
end
198+
end
199+
```
200+
201+
Have a look at [Show in App implementation](../lib/rails_admin/config/actions/show_in_app.rb) for a better idea of how you can take advantage of this.
202+
203+
Important: at some point of the application lifecycle, bindings can be nil:
204+
205+
- when RailsAdmin creates the route
206+
- when RailsAdmin defines the action in its controller
207+
208+
These bindings are available in all options.

docs/actiontext.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# ActionText
2+
3+
Rails 6 is shipped with a new rich text editor, called ActionText. RailsAdmin can make use of it in two ways.
4+
5+
## Easy-to-use setup
6+
7+
Follow [the official documentation](https://edgeguides.rubyonrails.org/action_text_overview.html#installation) to configure ActionText.
8+
9+
```bash
10+
$ rails action_text:install
11+
```
12+
13+
```ruby
14+
class Message < ApplicationRecord
15+
has_rich_text :content
16+
end
17+
```
18+
19+
That's it, RailsAdmin will show the rich text editor in the edit form of Message model.
20+
21+
Please note that this setup makes use of CDN-delivered assets for simplicity, hence it lacks some features like uploading attachments.
22+
23+
## Full-featured setup using Webpacker
24+
25+
First, you have to setup [Webpacker](https://github.com/rails/webpacker#installation) and [ActionText](https://edgeguides.rubyonrails.org/action_text_overview.html#installation) correctly. Watch out those issues if you're an early adopter:
26+
27+
- https://github.com/rails/webpacker/issues/2109
28+
- https://github.com/rails/rails/issues/36368
29+
30+
Create `app/javascript/packs/actiontext.js` with following content:
31+
32+
```javascript
33+
require("trix");
34+
require("@rails/actiontext");
35+
```
36+
37+
Configure your rich text field to pick up Webpacker-built asset:
38+
39+
```ruby
40+
config.model 'Message' do
41+
field :content do
42+
js_location { bindings[:view].asset_pack_path 'actiontext.js' }
43+
end
44+
end
45+
```
46+
47+
ActiveStorage Blob view generated by ActionText shows wrong image URL when used inside engine's path, so apply this patch to `app/views/active_storage/blobs/_blob.html.erb`:
48+
49+
```diff
50+
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
51+
<% if blob.representable? %>
52+
- <%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
53+
+ <%= image_tag polymorphic_url(blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]), script_name: nil) %>
54+
<% end %>
55+
56+
<figcaption class="attachment__caption">
57+
```
58+
59+
Drag and drop an image to the editor and you can now see the image uploaded and stored into ActiveStorage.
60+
61+
[More here](../lib/rails_admin/config/fields/types/action_text.rb)

0 commit comments

Comments
 (0)