Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activeadmin - Showing custom collection actions in index page

This is probably something very simple, but I can't seem to figure out why my collection actions are not showing up. As per the documentation it seems all I need to do is call the collection_actions method in the block passed to register. I want to add an action called "Notify All" to my user's admin page. Here's the code:

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

I don't see the notify_all action anywhere on the users page:

enter image description here

The route is there though. Do I need to customize index view to add collection action?

like image 913
septerr Avatar asked Feb 12 '14 05:02

septerr


2 Answers

Yes, You have to add something in user.rb config

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

This will add a link on the title bar beside New User link

like image 164
Muntasim Avatar answered Oct 17 '22 01:10

Muntasim


You need to modified your AA user.rb file as:

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
like image 45
Dheer Avatar answered Oct 17 '22 00:10

Dheer