Referință rapidă

Fișă de referință ActiveAdmin pentru Ruby on Rails

Ghid rapid de referință pentru ActiveAdmin în Ruby on Rails: domenii de listare, filtre laterale, acțiuni personalizate, coloane și funcții ajutătoare.

· Publicat

ActiveAdmin este un cadru de administrare popular pentru Ruby on Rails pentru construirea unor interfețe intuitive de back-office.

Domenii de listare (Scopes)

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

Filtre din bara laterală (Sidebar Filters)

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

Acțiuni personalizate pentru membri și colecții

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

Coloane de tabel personalizate

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

Etichete de stare (Status Tags)

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

Restricționarea acțiunilor CRUD implicite

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

Fișe de referință conexe

Subiecte conexe