Skip to content

Commit bc53141

Browse files
committed
Split the docs in the READM into multiple files so that we can expand on them.
This is the start of a new push for beter / deeper documentation. Now that we have them split out, we can revamp the README and the website.
1 parent 5c02721 commit bc53141

File tree

9 files changed

+382
-0
lines changed

9 files changed

+382
-0
lines changed

.yardopts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
lib/**/*.rb
2+
--protected
3+
--no-private
4+
--asset docs/images:images
5+
-
6+
README.rdoc
7+
CHANGELOG.rdoc
8+
docs/**/*.md

docs/1-general-configuration.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# General Configuration
2+
3+
## Admin Users
4+
5+
By default Active Admin will include Devise and create a new model called
6+
AdminUser. If you would like to use another name, you can pass it in to the
7+
installer through the user option:
8+
9+
$> rails generate active_admin:install UserClassName
10+
11+
If you don't want the generator to create any user classes:
12+
13+
$> rails generate active_admin:install --skip-users
14+
15+
## Authentication
16+
17+
Active Admin requires two settings to authenticate and use the current user
18+
within your application. Both are set in
19+
<tt>config/initializers/active_admin.rb</tt>. By default they are setup for use
20+
with Devise and a model named AdminUser. If you chose a different model name,
21+
you will need to update these settings.
22+
23+
Set the method that controllers should call to authenticate the current user
24+
with:
25+
26+
# config/initializers/active_admin.rb
27+
config.authentication_method = :authenticate_admin_user!
28+
29+
Set the method to call within the view to access the current admin user
30+
31+
# config/initializers/active_admin.rb
32+
config.current_user_method = :current_admin_user
33+
34+
Both of these settings can be set to false to turn off authentication.
35+
36+
# Turn off authentication all together
37+
config.authentication_method = false
38+
config.current_user_method = false
39+
40+
## Site Title
41+
42+
You can update the title used for the site in the initializer also. By default
43+
it is set to the name of your Rails.application class name.
44+
45+
# config/initializers/active_admin.rb
46+
config.site_title = "My Admin Site"
47+
48+
## Internationalization (I18n)
49+
50+
To internationalize Active Admin or to change default strings, you can copy
51+
lib/active_admin/locales/en.yml to your application config/locales directory and
52+
change its content. You can contribute to the project with your translations to!

docs/2-resource-customization.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Customize The Resource
2+
3+
## Rename the Resource
4+
5+
By default, any references to the resource (menu, routes, buttons, etc) in the
6+
interface will use the name of the class. You can rename the resource by using
7+
the <tt>:as</tt> option.
8+
9+
ActiveAdmin.register Post, :as => "Article"
10+
11+
The resource will then be available as /admin/articles
12+
13+
## Customize the Navigation
14+
15+
The resource will be displayed in the global navigation by default.
16+
17+
To disable the resource from being displayed in the global navigation:
18+
19+
ActiveAdmin.register Post do
20+
menu false
21+
end
22+
23+
To change the name of the label in the menu:
24+
25+
ActiveAdmin.register Post do
26+
menu :label => "My Posts"
27+
end
28+
29+
To add the menu as a child of another menu:
30+
31+
ActiveAdmin.register Post do
32+
menu :parent => "Blog"
33+
end
34+
35+
This will create the menu item if it doesn't exist yet.

docs/3-index-pages.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
# Customizing the Index Page
2+
3+
Filtering and listing resources is one of the most important tasks for
4+
administering a web application. Active Admin provides many different tools for
5+
you to build a compelling interface into your data for the admin staff.
6+
7+
Built in, Active Admin has the following index renderers:
8+
9+
* *Table*: A table drawn with each row being a resource
10+
* *Grid*: A set of rows and columns each cell being a resource
11+
* *Blocks*: A set of rows (not tabular) each row being a resource
12+
* *Blog*: A title and body content, similar to a blog index
13+
14+
All index pages also support scopes, filters, pagination, action items, and
15+
sidebar sections.
16+
17+
## Index as a Table
18+
19+
By default, the index page is a table with each of the models content columns and links to
20+
show, edit and delete the object. There are many ways to customize what gets
21+
displayed.
22+
23+
### Defining Columns
24+
25+
To display an attribute or a method on a resource, simply pass a symbol into the
26+
column method:
27+
28+
index do
29+
column :title
30+
end
31+
32+
If the default title does not work for you, pass it as the first argument:
33+
34+
index do
35+
column "My Custom Title", :title
36+
end
37+
38+
Sometimes calling methods just isn't enough and you need to write some view
39+
specific code. For example, say we wanted a colum called Title which holds a
40+
link to the posts admin screen.
41+
42+
The column method accepts a block as an argument which will then be rendered
43+
within the context of the view for each of the objects in the collection.
44+
45+
index do
46+
column "Title" do |post|
47+
link_to post.title, admin_post_path(post)
48+
end
49+
end
50+
51+
The block gets called once for each resource in the collection. The resource gets passed into
52+
the block as an argument.
53+
54+
55+
### Sorting
56+
57+
When a column is generated from an Active Record attribute, the table is
58+
sortable by default. If you are creating a custom column, you may need to give
59+
Active Admin a hint for how to sort the table.
60+
61+
If a column is defined using a block, you must pass the key to turn on sorting. The key
62+
is the attribute which gets used to sort objects using Active Record.
63+
64+
index do
65+
column "Title", :sortable => :title do |post|
66+
link_to post.title, admin_post_path(post)
67+
end
68+
end
69+
70+
You can turn off sorting on any column by passing false:
71+
72+
index do
73+
column :title, :sortable => false
74+
end
75+
76+
### Showing and Hiding Columns
77+
78+
The entire index block is rendered within the context of the view, so you can
79+
easily do things that show or hide columns based on the current context.
80+
81+
For example, if you were using CanCan:
82+
83+
index do
84+
column :title, :sortable => false
85+
if can? :manage, Post
86+
column :some_secret_data
87+
end
88+
end
89+
90+
## Index as a Grid
91+
92+
Sometimes you want to display the index screen for a set of resources as a grid
93+
(possibly a grid of thumbnail images). To do so, use the :grid option for the
94+
index block.
95+
96+
index :as => :grid do |product|
97+
link_to(image_tag(product.image_path), admin_products_path(product))
98+
end
99+
100+
The block is rendered within a cell in the grid once for each resource in the
101+
collection. The resource is passed into the block for you to use in the view.
102+
103+
You can customize the number of colums that are rendered using the columns
104+
option:
105+
106+
index :as => :grid, :columns => 5 do |product|
107+
link_to(image_tag(product.image_path), admin_products_path(product))
108+
end
109+
110+
111+
## Index as a Block
112+
113+
If you want to fully customize the display of your resources on the index
114+
screen, Index as a Block allows you to render a block of content for each
115+
resource.
116+
117+
index :as => :block do |product|
118+
div :for => product do
119+
h2 auto_link(product.title)
120+
div do
121+
simple_format product.description
122+
end
123+
end
124+
end
125+
126+
## Index Filters
127+
128+
By default the index screen includes a "Filters" sidebar on the right hand side
129+
with a filter for each attribute of the registered model. You can customize the
130+
filters that are displayed as well as the type of widgets they use.
131+
132+
To display a filter for an attribute, use the filter method
133+
134+
ActiveAdmin.register Post do
135+
filter :title
136+
end
137+
138+
Out of the box, Active Admin supports the following filter types:
139+
140+
* *:string* - A search field
141+
* *:date_range* - A start and end date field with calendar inputs
142+
* *:numeric* - A drop down for selecting "Equal To", "Greater Than" or "Less
143+
Than" and an input for a value.
144+
* *:select* - A drop down which filters based on a selected item in a collection
145+
or all.
146+
* *:check_boxes* - A list of check boxes users can turn on and off to filter
147+
148+
By default, Active Admin will pick the most relevant filter based on the
149+
attribute type. You can force the type by passing the :as option.
150+
151+
filter :author, :as => :check_boxes
152+
153+
The :check_boxes and :select types accept options for the collection. By default
154+
it attempts to create a collection based on an association. But you can pass in
155+
the collection as a proc to be called at render time.
156+
157+
# Will call available
158+
filter :author, :as => :check_boxes, :collection => proc { Author.all }
159+
160+
You can change the filter label by passing a label option:
161+
162+
filter :author, :label => 'Author'
163+
164+
By default, Active Admin will try to use ActiveModel I18n to determine the label.

docs/4-csv-format.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Customizing the CSV format
2+
3+
Customizing the CSV format is as simple as customizing the index page.
4+
5+
csv do
6+
column :name
7+
column("Author") { |post| post.author.full_name }
8+
end

docs/5-forms.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Customizing the Form
2+
3+
Active Admin gives complete control over the output of the form by creating a thin DSL on top of
4+
the fabulous DSL created by Formtastic (http://github.com/justinfrench/formtastic).
5+
6+
ActiveAdmin.register Post do
7+
8+
form do |f|
9+
f.inputs "Details" do
10+
f.input :title
11+
f.input :published_at, :label => "Publish Post At"
12+
f.input :category
13+
end
14+
f.inputs "Content" do
15+
f.input :body
16+
end
17+
f.buttons
18+
end
19+
20+
end
21+
22+
Please view the documentation for Formtastic to see all the wonderful things you can do:
23+
http://github.com/justinfrench/formtastic
24+
25+
If you require a more custom form than can be provided through the DSL, you can pass
26+
a partial in to render the form yourself.
27+
28+
For example:
29+
30+
ActiveAdmin.register Post do
31+
form :partial => "form"
32+
end
33+
34+
Then implement app/views/admin/posts/_form.html.erb:
35+
36+
<%= semantic_form_for [:admin, @post] do |f| %>
37+
<%= f.inputs :title, :body %>
38+
<%= f.buttons :commit %>
39+
<% end %>

docs/6-show-screens.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Customizing the Show Screen
2+
3+
Customizing the show screen is as simple as implementing the show block:
4+
5+
ActiveAdmin.register Post do
6+
show do
7+
h3 post.title
8+
div do
9+
simple_format post.body
10+
end
11+
end
12+
end
13+
14+
The show block is rendered within the context of the view and uses the Arbre HTML DSL. You
15+
can also render a partial at any point.
16+
17+
ActiveAdmin.register Post do
18+
show do
19+
# renders app/views/admin/posts/_some_partial.html.erb
20+
render "some_partial"
21+
end
22+
end

docs/7-sidebars.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Sidebar Sections
2+
3+
To add a sidebar section to all the screen within a section, use the sidebar method:
4+
5+
sidebar :help do
6+
"Need help? Email us at [email protected]"
7+
end
8+
9+
This will generate a sidebar section on each screen of the resource. With the block as
10+
the contents of the section. The first argument is the section title.
11+
12+
You can also use Arbre syntax to define the content.
13+
14+
sidebar :help do
15+
ul do
16+
li "Second List First Item"
17+
li "Second List Second Item"
18+
end
19+
end
20+
21+
Sidebar sections can be rendered on a specific action by using the :only or :except
22+
options.
23+
24+
sidebar :help, :only => :index do
25+
"Need help? Email us at [email protected]"
26+
end
27+
28+
If you only pass a symbol, Active Admin will attempt to locate a partial to render.
29+
30+
# Will render app/views/admin/posts/_help_sidebar.html.erb
31+
sidebar :help
32+
33+
Or you can pass your own custom partial to render.
34+
35+
sidebar :help, :partial => "custom_help_partial"

docs/8-custom-actions.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Add collection and member actions
2+
3+
## Add Custom Collection Action
4+
5+
To add a collection action, use the collection_action method:
6+
7+
collection_action :import_csv do
8+
# do csv import
9+
redirect_to :action => :index, :notice => "CSV imported successfully!"
10+
end
11+
12+
## Add Custom Member Action
13+
14+
To add a member action, use the member_action method:
15+
16+
member_action :lock, :method => :post do
17+
resource.lock!
18+
redirect_to :action => :show, :notice => "Locked!"
19+
end

0 commit comments

Comments
 (0)