مرجع سريع

ورقة غش ActiveAdmin لإطار عمل Ruby on Rails

دليل مرجعي سريع لإطار عمل ActiveAdmin في Ruby on Rails، يغطي نطاقات التصفية، فلاتر الشريط الجانبي، الإجراءات المخصصة، وتخصيص الجداول.

· تاريخ النشر

ActiveAdmin هو إطار عمل إدارة شهير لـ Ruby on Rails لبناء لوحات تحكم وإدارات خلفية مريحة ومرنة.

نطاقات تصفية القوائم (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

أوراق غش ذات صلة

موضوعات ذات صلة