Rails | ActiveAdmin |Custom checkboxes collection for array field

Sometimes you might want to store coherent information in single string field in database. For such fields you might want the Admin to have some mechanism to update.

In Rails you can have Array field like

# in migration file
# Array Types
t.string :open_days,       array: true, default: []
t.string :payment_options, array: true, default: []
t.text   :vehicle_vendors, array: true, default: []
t.text   :services_ids,    array: true, default: []

for such fields the form builder would look like Continue reading

Rails : Formtastic : Single Table Inheritance : Issues and solution

I have been using Formtastic from the beginning and then some feature changes came across my application. I had a model called `DrugTest` then I also needed to implement additional drugtest (hair test and alcohol test). So I thought STI would be a perfect match to my scenario.

I created two classes `AdditionalHairDrugTest` and `AdditionalAlcoholDrugTest` derived from the model `DrugTest`

# == Schema Information
#
# Table name: drug_tests
# type :string
# ...
class AdditionalAlcoholDrugTest < DrugTest
 belongs_to :pact
 belongs_to :user
 default_scope -> {where(type: :AdditionalAlcoholDrugTest)}

 def is_additional?
   true
 end
end

Now I encountered this error Continue reading