省略attr_accessible :block_ids
並在底部應用替代解決方案適用於我。
PS:Rails的4.2.0與rails_admin 0.6.6
class Grid < ActiveRecord::Base
has_many :block_grid_associations, :dependent => :delete_all, :autosave => true, :include => :block
has_many :blocks, :through => :block_grid_associations
def block_ids=(ids)
unless (ids = ids.map(&:to_i).select { |i| i>0 }) == (current_ids = block_grid_associations.map(&:block_id))
(current_ids - ids).each { |id| block_grid_associations.select{|b|b.block_id == id}.first.mark_for_destruction }
ids.each_with_index do |id, index|
if current_ids.include? (id)
block_grid_associations.select { |b| b.block_id == id }.first.position = (index+1)
else
block_grid_associations.build({:block_id => id, :position => (index+1)})
end
end
end
end
rails_admin do
configure :block_grid_associations do
visible(false)
end
configure :blocks do
orderable(true) # only for multiselect widget currently. Will add the possibility to order blocks
# configuration here
end
end
end