From eaedad5d644d78c34a53516ba1d301835a295d49 Mon Sep 17 00:00:00 2001 From: "Rico Sta. Cruz" Date: Fri, 27 Oct 2017 11:30:58 +0800 Subject: [PATCH] activeadmin: fix title --- activeadmin.md | 103 ++++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/activeadmin.md b/activeadmin.md index 2d66aea5..73333d7f 100644 --- a/activeadmin.md +++ b/activeadmin.md @@ -1,72 +1,97 @@ +--- title: ActiveAdmin category: Ruby +layout: 2017/sheet --- ### Listing scopes Allows you to filter listings by a certain scope. +{: .-setup} - scope :draft - scope :for_approval +```ruby +scope :draft +scope :for_approval +``` - scope :public, if: ->{ current_admin_user.can?(...) } - scope "Unapproved", :pending - scope("Published") { |books| books.where(:published: true) } +```ruby +scope :public, if: ->{ current_admin_user.can?(...) } +scope "Unapproved", :pending +scope("Published") { |books| books.where(:published: true) } +``` ### Sidebar filters - filter :email - filter :username +```ruby +filter :email +filter :username +``` ### Custom actions You can define custom actions for models. +{: .-setup} - before_filter only: [:show, :edit, :publish] do - @post = Post.find(params[:id]) - end +```ruby +before_filter only: [:show, :edit, :publish] do + @post = Post.find(params[:id]) +end +``` -Make the route: +#### Make the route - member_action :publish, method: :put do - @post.publish! - redirect_to admin_posts_path, notice: "The post '#{@post}' has been published!" - end +```ruby +member_action :publish, method: :put do + @post.publish! + 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 - column do |post| - link_to 'Publish', publish_admin_post_path(post), method: :put - end - end +```ruby +index do + column do |post| + link_to 'Publish', publish_admin_post_path(post), method: :put + end +end +``` -And link it in show/edit: +#### And link it in show/edit - action_item only: [:edit, :show] do - @post = Post.find(params[:id]) - link_to 'Publish', publish_admin_post_path(post), method: :put - end +```ruby +action_item only: [:edit, :show] do + @post = Post.find(params[:id]) + link_to 'Publish', publish_admin_post_path(post), method: :put +end +``` ### Columns - column :foo +```ruby +column :foo +``` - column :title, sortable: :name do |post| - strong post.title - end +```ruby +column :title, sortable: :name do |post| + strong post.title +end +``` ### Other helpers - # Grey, green, orange, red - status_tag "Done" - status_tag "Finished", :ok - status_tag "You", :warn - status_tag "Failed", :error +```ruby +status_tag "Done" # Gray +status_tag "Finished", :ok # Green +status_tag "You", :warn # Orange +status_tag "Failed", :error # Red +``` ### Disabling 'new post' - ActiveAdmin.register Post do - actions :index, :edit - # or: config.clear_action_items! - end +```ruby +ActiveAdmin.register Post do + actions :index, :edit + # or: config.clear_action_items! +end +```