Activeadmin - 在索引页面中显示自定义集合操作

时间:2014-02-12 05:56:55

标签: ruby-on-rails activeadmin

这可能非常简单,但我似乎无法弄清楚为什么我的收集行动没有显示出来。根据文档,我需要做的就是调用传递给寄存器的块中的collection_actions方法。我想在我的用户的管理页面中添加一个名为“Notify All”的操作。 这是代码:

ActiveAdmin.register User do

  menu :label => "Users", :priority => 3

  filter :twitter_id
  filter :facebook_id
  filter :created_at
  filter :allows_notifications
  filter :created_at

  actions :all, except: [:destroy, :new]

  collection_action :notify_all, :method => :post do
    puts "notifying...."
  end

  batch_action :flag do |selection|
    puts "flagging...."
  end

  index do
    selectable_column
    column "", :sortable => false do |user|
      "<img src='#{user.avatar_url}' alt='user avatar' style='width:24px; height:24px;'/>".html_safe
    end
    column :uuid
    column :twitter_id
    column :facebook_id
    column :allow_notifications do |user| user.allow_notifications ? "true" : "false" end
    column :blocked do |user| user.blocked ? "true" : "false" end
    column :created_at

    default_actions
  end

  form do |f|
    f.inputs :allow_notifications,:blocked
    f.buttons
  end

  show do
    attributes_table do
      row "Avatar" do |user|
        "<img src='#{user.avatar_url}' alt='user avatar'/>".html_safe
      end
      row :uuid
      row :twitter_id
      row :facebook_id
      row :allow_notifications do |user| user.allow_notifications ? "true" : "false" end
      row :blocked do |user| user.blocked ? "true" : "false" end
      row :created_at
      row "Active Events" do |user| user.active_events.size end
      row "Conversations" do |user| user.conversations.size end
      row "Comments" do |user| user.comments.size end
    end
    active_admin_comments
  end


end

我在用户页面的任何地方都没有看到notify_all操作:

enter image description here

虽然路线在那里。我是否需要自定义索引视图以添加集合操作?

2 个答案:

答案 0 :(得分:13)

是的,您必须在user.rb config

中添加内容
action_item :only => :index do
  link_to('Notify All', notify_all_admin_users_path)
end

这将在新用户链接旁边的标题栏上添加一个链接

答案 1 :(得分:4)

您需要将AA user.rb文件修改为:

action_item do
  link_to 'Notify All', admin_notify_all_path(path according to your routes)
end


collection_action :notify_all, :method => :post do
  puts "notifying...."
end