I have a model for Experiment and the schema looks like this:
create_table "experiments", id: :serial, force: :cascade do |t|
t.string "name"
t.string "state"
t.jsonb "experiment_conditions"
end
As you can see in the schema, experiment_conditions is type jsonb. I want the user to be able to name the key whatever they want and give it a number (percentage of 100).
For example: {"control": 10, "variant": 90}
or {"control": 50, "other": 50}
The issue I am having is with the form in the view file. I know that I need it to follow this pattern:
<%= form.text_field_tag "experiment[experiment_conditions][name_of_key]", [experiment_value] %>
But I can't figure out a way to allow the user to enter both the key and value of a nested object in a rails form. I've considered using the cocoon gem, but from the looks of it, that gem only works with ActiveRecord associated models. Anyhow, thank you in advance!
Note: I'm hoping to find a solution without using javascript