【发布时间】:2014-02-12 05:56:55
【问题描述】:
这可能是非常简单的事情,但我似乎无法弄清楚为什么我的收集操作没有出现。根据文档,似乎我需要做的就是在传递给注册的块中调用 collection_actions 方法。我想在我的用户的管理页面中添加一个名为“全部通知”的操作。 代码如下:
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 操作:
路线在那里。我需要自定义索引视图来添加集合操作吗?
【问题讨论】:
-
这是一个动作,就像一个普通的控制器动作。它不会显示在视图中,除非您放置一些链接、按钮 ..etc 并将其绑定以触发操作
-
我明白了。我开始认为这是我需要做的。 Rails 让你习惯于期待魔法。 :|