ActiveAdmincheatsheet
贡献者:BAI
ActiveAdmin
根据 Scope 过滤数据
RUBYscope :draftscope :for_approval
RUBYscope :public, if: ->{ current_admin_user.can?(...) }scope "Unapproved", :pendingscope("Published") { |books| books.where(:published: true) }
侧边栏过滤器
RUBYfilter :emailfilter :username
自定义操作
RUBYbefore_filter only: [:show, :edit, :publish] do @post = Post.find(params[:id])end
设置路由
RUBYmember_action :publish, method: :put do @post.publish! redirect_to admin_posts_path, notice: "The post '#{@post}' has been published!"end
在目录页添加链接
RUBYindex do column do |post| link_to 'Publish', publish_admin_post_path(post), method: :put endend
在详情/编辑页显示链接
RUBYaction_item only: [:edit, :show] do @post = Post.find(params[:id]) link_to 'Publish', publish_admin_post_path(post), method: :putend
列(Column)
RUBYcolumn :foo
RUBYcolumn :title, sortable: :name do |post| strong post.titleend
其他的帮助方法
RUBYstatus_tag "Done" # Graystatus_tag "Finished", :ok # Greenstatus_tag "You", :warn # Orangestatus_tag "Failed", :error # Red
指定特定行为
RUBYActiveAdmin.register Post do actions :index, :edit # or: config.clear_action_items!end