activeadmin: fix title

This commit is contained in:
Rico Sta. Cruz 2017-10-27 11:30:58 +08:00
parent 687dd18a86
commit eaedad5d64
No known key found for this signature in database
GPG Key ID: CAAD38AE2962619A
1 changed files with 64 additions and 39 deletions

View File

@ -1,72 +1,97 @@
---
title: ActiveAdmin title: ActiveAdmin
category: Ruby category: Ruby
layout: 2017/sheet
--- ---
### Listing scopes ### Listing scopes
Allows you to filter listings by a certain scope. Allows you to filter listings by a certain scope.
{: .-setup}
scope :draft ```ruby
scope :for_approval scope :draft
scope :for_approval
```
scope :public, if: ->{ current_admin_user.can?(...) } ```ruby
scope "Unapproved", :pending scope :public, if: ->{ current_admin_user.can?(...) }
scope("Published") { |books| books.where(:published: true) } scope "Unapproved", :pending
scope("Published") { |books| books.where(:published: true) }
```
### Sidebar filters ### Sidebar filters
filter :email ```ruby
filter :username filter :email
filter :username
```
### Custom actions ### Custom actions
You can define custom actions for models. You can define custom actions for models.
{: .-setup}
before_filter only: [:show, :edit, :publish] do ```ruby
@post = Post.find(params[:id]) before_filter only: [:show, :edit, :publish] do
end @post = Post.find(params[:id])
end
```
Make the route: #### Make the route
member_action :publish, method: :put do ```ruby
@post.publish! member_action :publish, method: :put do
redirect_to admin_posts_path, notice: "The post '#{@post}' has been published!" @post.publish!
end redirect_to admin_posts_path, notice: "The post '#{@post}' has been published!"
end
```
Link it in the index: #### Link it in the index
index do ```ruby
column do |post| index do
link_to 'Publish', publish_admin_post_path(post), method: :put column do |post|
end link_to 'Publish', publish_admin_post_path(post), method: :put
end end
end
```
And link it in show/edit: #### And link it in show/edit
action_item only: [:edit, :show] do ```ruby
@post = Post.find(params[:id]) action_item only: [:edit, :show] do
link_to 'Publish', publish_admin_post_path(post), method: :put @post = Post.find(params[:id])
end link_to 'Publish', publish_admin_post_path(post), method: :put
end
```
### Columns ### Columns
column :foo ```ruby
column :foo
```
column :title, sortable: :name do |post| ```ruby
strong post.title column :title, sortable: :name do |post|
end strong post.title
end
```
### Other helpers ### Other helpers
# Grey, green, orange, red ```ruby
status_tag "Done" status_tag "Done" # Gray
status_tag "Finished", :ok status_tag "Finished", :ok # Green
status_tag "You", :warn status_tag "You", :warn # Orange
status_tag "Failed", :error status_tag "Failed", :error # Red
```
### Disabling 'new post' ### Disabling 'new post'
ActiveAdmin.register Post do ```ruby
actions :index, :edit ActiveAdmin.register Post do
# or: config.clear_action_items! actions :index, :edit
end # or: config.clear_action_items!
end
```