Permalink
Browse files

update index docs to use GFM 🍰

  • Loading branch information...
seanlinsley committed Oct 27, 2013
1 parent c994f8c commit f80256f949b30cbf12aec7be6ef8a0fd0d530ccd
View
@@ -22,36 +22,42 @@ automatically build links at the top of the default index page. Including
multiple views is simple and requires creating multiple index components in
your resource.
index do
id_column
column :image_title
default_actions
end
index :as => :grid do |product|
link_to(image_tag(product.image_path), admin_product_path(product))
end
```ruby
index do
id_column
column :image_title
default_actions
end
index as: :grid do |product|
link_to image_tag(product.image_path), admin_product_path(product)
end
```
The first index component will be the default index page unless you indicate
otherwise by setting :default to true.
index do
column :image_title
default_actions
end
```ruby
index do
column :image_title
default_actions
end
index :as => :grid, :default => true do |product|
link_to(image_tag(product.image_path), admin_product_path(product))
end
index as: :grid, default: true do |product|
link_to image_tag(product.image_path), admin_product_path(product)
end
```
Active Admin does not limit the index page to be a table, block, blog or grid.
If you've [created your own index page](3-index-pages/create-an-index.md) it can be included by setting :as to the
class of the index component you created.
If you've [created your own index page](3-index-pages/create-an-index.md) it
can be included by setting :as to the class of the index component you created.
index :as => ActiveAdmin::Views::IndexAsTable do
column :image_title
default_actions
end
```ruby
index as: ActiveAdmin::Views::IndexAsTable do
column :image_title
default_actions
end
```
## Index Filters
@@ -61,9 +67,11 @@ filters that are displayed as well as the type of widgets they use.
To display a filter for an attribute, use the filter method
ActiveAdmin.register Post do
filter :title
end
```ruby
ActiveAdmin.register Post do
filter :title
end
```
Out of the box, Active Admin supports the following filter types:
@@ -78,18 +86,23 @@ Out of the box, Active Admin supports the following filter types:
By default, Active Admin will pick the most relevant filter based on the
attribute type. You can force the type by passing the :as option.
filter :author, :as => :check_boxes
```ruby
filter :author, as: :check_boxes
```
The :check_boxes and :select types accept options for the collection. By default
it attempts to create a collection based on an association. But you can pass in
the collection as a proc to be called at render time.
# Will call available
filter :author, :as => :check_boxes, :collection => proc { Author.all }
```ruby
filter :author, as: :check_boxes, collection: proc { Author.all }
```
You can change the filter label by passing a label option:
filter :author, :label => 'Author'
```ruby
filter :author, label: 'Something else'
```
By default, Active Admin will try to use ActiveModel I18n to determine the label.
@@ -98,101 +111,96 @@ application.
To disable for a specific resource:
ActiveAdmin.register Post do
config.filters = false
end
```ruby
ActiveAdmin.register Post do
config.filters = false
end
```
To disable for a namespace, in the initializer:
ActiveAdmin.setup do |config|
config.namespace :my_namespace do |my_namespace|
my_namespace.filters = false
end
end
```ruby
ActiveAdmin.setup do |config|
config.namespace :my_namespace do |my_namespace|
my_namespace.filters = false
end
end
```
Or to disable for the entire application:
ActiveAdmin.setup do |config|
config.filters = false
end
```ruby
ActiveAdmin.setup do |config|
config.filters = false
end
```
You can also add a filter and still preserve the default filters:
preserve_default_filters!
filter :author
```ruby
preserve_default_filters!
filter :author
```
## Index default sort order
You can define the default sort order for index pages:
ActiveAdmin.register Post do
config.sort_order = "name_asc"
end
```ruby
ActiveAdmin.register Post do
config.sort_order = 'name asc'
end
```
## Index pagination
You can set the number of records per page per resources:
ActiveAdmin.register Post do
config.per_page = 10
end
```ruby
ActiveAdmin.register Post do
config.per_page = 10
end
```
You can also disable pagination:
ActiveAdmin.register Post do
config.paginate = false
end
If you have a very large database, you might want to disable SELECT COUNT(*) queries caused by the pagination info at the bottom of the page:
ActiveAdmin.register Post do
# disable pagination total
index :pagination_total => false do
#...
end
end
## Disable CSV, XML and JSON export
```ruby
ActiveAdmin.register Post do
config.paginate = false
end
```
You can remove links to download CSV, XML and JSON exports:
If you have a very large database, you might want to disable SELECT COUNT(*)
queries caused by the pagination info at the bottom of the page:
index :download_links => false do
end
```ruby
ActiveAdmin.register Post do
index pagination_total: false do
# ...
end
end
```
## Customizing Download Links
There are multiple ways to either remove the download links per resource listing, or customize the formats that are shown. Customize the formats by passing an array of symbols, or pass false to hide entirely.
Customizing the download links per resource:
ActiveAdmin.register Post do
# hide the links entirely
index :download_links => false
# only show a PDF export
index :download_links => [:pdf]
# hide/show links based on block
index :download_links => proc { current_admin_user.can_view_download_links? }
end
If you want to customize download links for every resource throughout the application, configure that in the `active_admin` initializer.
You can easily remove or customize the download links you want displayed:
ActiveAdmin.setup do |config|
```ruby
# Per resource:
ActiveAdmin.register Post do
# Disable entirely
config.download_links = false
index download_links: false
index download_links: [:pdf]
index download_links: proc{ current_user.can_view_download_links? }
# Want PDF added to default download links
config.download_links = [:csv, :xml, :json, :pdf]
end
# hide/show links based on block
index :download_links => proc { current_admin_user.can_view_download_links? }
# For the entire application:
ActiveAdmin.setup do |config|
end
config.download_links = false
config.download_links = [:csv, :xml, :json, :pdf]
config.download_links = proc { current_user.can_view_download_links? }
end
```
@@ -10,12 +10,12 @@ If you want to fully customize the display of your resources on the index
screen, Index as a Block allows you to render a block of content for each
resource.
index :as => :block do |product|
div :for => product do
resource_selection_cell product
h2 auto_link(product.title)
div do
simple_format product.description
end
end
end
```ruby
index as: :block do |product|
div for: product do
resource_selection_cell product
h2 auto_link product.title
div simple_format product.description
end
end
```
@@ -9,36 +9,38 @@
Render your index page as a set of posts. The post has two main options:
title and body.
index :as => :blog do
title :my_title # Calls #my_title on each resource
body :my_body # Calls #my_body on each resource
end
```ruby
index as: :blog do
title :my_title # Calls #my_title on each resource
body :my_body # Calls #my_body on each resource
end
```
## Post Title
The title is the content that will be rendered within a link to the
resource. There are two main ways to set the content for the title
First, you can pass in a method to be called on your
resource. For example:
index :as => :blog do
title :a_method_to_call
end
First, you can pass in a method to be called on your resource. For example:
This will result in the title of the post being the return value of
Resource#a_method_to_call
```ruby
index as: :blog do
title :a_method_to_call
end
```
Second, you can pass a block to the tile option which will then be
used as the contents fo the title. The resource being rendered
is passed in to the block. For Example:
index :as => :blog do
title do |post|
span post.title, :class => 'title'
span post.created_at, :class => 'created_at'
end
end
```ruby
index as: :blog do
title do |post|
span post.title, class: 'title'
span post.created_at, class: 'created_at'
end
end
```
## Post Body
@@ -47,19 +49,23 @@ style of options work as the Post Title above.
Call a method on the resource as the body:
index :as => :blog do
title :my_title
body :my_body # Return value of #my_body will be the body
end
```ruby
index as: :blog do
title :my_title
body :my_body
end
```
Or, render a block as the body:
index :as => :blog do
title :my_title
body do |post|
div truncate(post.title)
div :class => 'meta' do
span "Post in #{post.categories.join(', ')}"
end
end
```ruby
index as: :blog do
title :my_title
body do |post|
div truncate post.title
div class: 'meta' do
span "Post in #{post.categories.join(', ')}"
end
end
end
```
Oops, something went wrong.

0 comments on commit f80256f

Please sign in to comment.