Formtastic / ActiveAdmin multi-select many, many questions about setting flags

I use activeadmin, and it has formtastic built-in, like many of you who know it. I have a model called Project that has a lot in common with ProjectResources.

My custom “editing” and “creating” forms in the active admin for the project looks like this.

form do |f|
          f.inputs "Project" do
            f.input :name, :input_html => { :readonly => true }
          end
          f.inputs "Resources" do
            f.input :id, :label => "Selected Resources",  
                :as => :check_boxes, 
                :multiple => true, 
                :collection => ProjectResource.all,
                :selected => @resources
          end
          f.buttons
    end

My checkboxes display very well, and at the moment I am not getting any errors. The problem, if you might have guessed, is that when rendering the edit page, I would like to show the elements in the checkbox area as “selected” if the project already has ProjectResource as an association.

. activeadmin, formtastic . (2.2.0, 2.1.1, 2.1.0, 2.0.2, 1.2.4)

, activeadmin . - .

+5
1

:

ActiveAdmin.register Subscription do

  form do |f|
    f.inputs do
      f.input :users, as: :check_boxes
      # other fields...
    end
    f.buttons
  end
end

.

:

-User class

class User < ActiveRecord::Base
  has_and_belongs_to_many :users
  attr_accessible :fields...
end

-

class Subscription < ActiveRecord::Base
  has_and_belongs_to_many :subscriptions
  attr_accessible :fields...
end

PS ActiveAdmin 0.4.2 Formtastic 2.0.2.

+9

All Articles