ActiveAdmin批处理操作动态表单 [英] ActiveAdmin Batch Action Dynamic Form
问题描述
我将Rails 4与ActiveAdmin一起使用。我使用自定义表单创建了一个批处理操作,以为每个选定的设备创建一个带有内部版本号的任务。这是我的代码:
ActiveAdmin.register Device do
def get_builds
builds = []
Build.all.each做| build |
构建<< [
[#{build.resource}-#{build.version}]#{build.file_name},
build.id
]
结束
return builds
end
batch_action:create_task,形式:{
build:get_builds()
}做| id,输入|
build = Build.find(inputs [:build])
Device.where(id:ids).each | device |
Task.create({
device:device,
build:build
})
end
redirect_to admin_tasks_path
end
结束
我的问题是内置列表 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ 这当然是因为form参数仅对我的函数进行一次评估,但找不到任何有关动态表单的文档。 ActiveAdmin在加载时将类缓存在内存中,因此生成的版本仅计算一次。要在每次加载时重新计算,请将 I am using rails 4 with ActiveAdmin. I created a batch action using a custom form to create a Task with a Build number for every selected Device. Here's what my code looks like: My problem is that the list of build in the batch action's form is not refreshing. When I start my app it does have a list of all the available builds but if I add or remove a build, the build list won't be refreshed. It is of course because the form parameter evaluate my function only once but I can't find any documentation about having a "dynamic" form. ActiveAdmin is caching the class in memory on load, so the builds only get calculated once. To re-calculate on each load, pass a
这篇关于ActiveAdmin批处理操作动态表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
lambda
传递为 form
的值,例如:
form_lambda = lambda做
构建= Build.all.map做| build |
[#{build.resource}-#{build.version}#{build.file_name},build.id]
end
{build:builds}
end
batch_action:create_task,形式:form_lambda do
#...
end
ActiveAdmin.register Device do
def get_builds
builds = []
Build.all.each do |build|
builds << [
"[#{build.resource} - #{build.version}] #{build.file_name}",
build.id
]
end
return builds
end
batch_action :create_task, form: {
build: get_builds()
} do |ids, inputs|
build = Build.find(inputs[:build])
Device.where(id: ids).each do |device|
Task.create({
device: device,
build: build
})
end
redirect_to admin_tasks_path
end
end
lambda
as the value of form
, e.g:form_lambda = lambda do
builds = Build.all.map do |build|
["#{ build.resource } - #{ build.version } #{ build.file_name }", build.id]
end
{ build: builds }
end
batch_action :create_task, form: form_lambda do
# ...
end