ActiveAdmin Dynamic Group Action Form

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 each selected device. This is what my code looks like:

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

My problem is that the build list in the form of a batch action is not refreshing. When I launch my application, it has a list of all available assemblies, but if I add or remove an assembly, the assembly list will not be updated.

This, of course, is because the form parameter evaluates my function only once, but I cannot find documentation about the presence of a “dynamic” form.

+4
source share
1

ActiveAdmin , . , lambda form, :

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
+6

Source: https://habr.com/ru/post/1607907/


All Articles