Snabbreferens

ActiveAdmin fusklapp för Ruby on Rails

Snabbreferens för ActiveAdmin i Ruby on Rails: listningsomfång, sidofältsfilter, anpassade åtgärder, tabellkolumner och vyhjälpare.

· Publicerad

ActiveAdmin är ett populärt administrationsramverk för Ruby on Rails för att bygga intuitiva backoffice-gränssnitt.

Listningsomfång (Listing Scopes)

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

Sidofältsfilter (Sidebar Filters)

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

Anpassade medlems- och samlingsåtgärder

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

Anpassade tabellkolumner

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

Statusmärken (Status Tags)

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

Begränsa standard CRUD-åtgärder

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

Relaterade fusklappar

Relaterade ämnen