Snelle referentie

ActiveAdmin spiekbriefje voor Ruby on Rails

Snelle naslaggids voor ActiveAdmin in Ruby on Rails: listing scopes, zijbalkfilters, aangepaste acties, tabelkolommen en view helpers.

· Gepubliceerd

ActiveAdmin is een populair administratieframework voor Ruby on Rails voor het bouwen van intuïtieve backoffice-interfaces.

Listing Scopes (Filterbereiken)

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

Zijbalkfilters (Sidebar Filters)

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

Aangepaste Member- & Collection-acties

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

Aangepaste tabelkolommen

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

Status-tags (Status-badges)

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

Beperken van standaard CRUD-acties

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

Gerelateerde spiekbriefjes

Verwante onderwerpen