빠른 참조

ActiveAdmin 치트시트 (Ruby on Rails 관리자 대시보드)

Ruby on Rails의 ActiveAdmin 관리자 프레임워크 핵심 치트시트. 목록 스코프, 사이드바 필터, 커스텀 액션, 테이블 컬럼 및 뷰 헬퍼를 정리합니다.

· 게시일

ActiveAdmin은 직관적인 백오피스 관리 인터페이스를 구축하기 위한 Ruby on Rails 관리 프레임워크입니다.

목록 스코프 (Listing Scopes)

scope :draft
scope :for_approval
scope :public, if: -> { current_admin_user.can?(...) }
scope "Unapproved", :pending
scope("Published") { |books| books.where(published: true) }

사이드바 필터 (Sidebar Filters)

filter :email
filter :username
filter :created_at
filter :author, as: :select, collection: -> { Author.all }

커스텀 멤버 및 컬렉션 액션 (Custom Actions)

before_action only: [:show, :edit, :publish] do
  @post = Post.find(params[:id])
end
# Define member action
member_action :publish, method: :put do
  @post.publish!
  redirect_to admin_posts_path, notice: "The post '#{@post.title}' has been published!"
end
# Index View table actions
index do
  selectable_column
  id_column
  column :title
  column do |post|
    link_to 'Publish', publish_admin_post_path(post), method: :put
  end
  actions
end
# Show / Edit Action item button
action_item :publish, only: [:edit, :show] do
  link_to 'Publish', publish_admin_post_path(resource), method: :put unless resource.published?
end

커스텀 테이블 컬럼 (Custom Columns)

column :foo
column :title, sortable: :title do |post|
  strong post.title
end

상태 태그 (Status Tags)

status_tag "Draft"             # Default Gray
status_tag "Published", :ok    # Green
status_tag "Pending", :warn    # Orange
status_tag "Failed", :error    # Red

기본 CRUD 액션 제한

ActiveAdmin.register Post do
  actions :index, :show, :edit
  # config.clear_action_items!
end

관련 치트시트

관련 주제