2014-02-12 109 views
5

这可能很简单,但我似乎无法弄清楚为什么我的收集操作没有显示出来。根据文档,似乎我需要做的就是调用传递给注册的块中的collection_actions方法。我想添加一个名为“通知全部”的操作到我的用户的管理页面。 下面的代码:Activeadmin - 在索引页面显示自定义收集操作

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

路线是存在的,但。我是否需要自定义索引视图以添加收集操作?

+1

这是一个动作,就像一个常规的控制器操作。它不会在视图中显示,除非您放置一些链接,按钮..etc并将其绑定到触发我看到的动作 – Nimir

+0

。我开始认为这是我需要做的。 Rails让你习惯于期待魔法。 :| – septerr

回答

12

是的,你必须在user.rb配置

action_item :only => :index do 
    link_to('Notify All', notify_all_admin_users_path) 
end 

这将增加新用户链接旁边的标题栏

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