2014-02-12 57 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