I have two tables: groups and series. A serie has_many groups and a group belongs_to a serie.
I’m using Formstastic to automatically generate a <select> with all the series so the user will be able to select the serie related to the group being created.
But a serie belongs_to the table units, which has_many series. Since series have the same name, it will not possible for the user to know exactly which serie he’s choosing in the <select>, unless he knows to which unit a specific serie belongs to. For that I’d like every <option> to have the following format:
<option value="serie_id">serie.name – unit.name</option>
What I have until now (and working) is:
ActiveAdmin.register Group do
form do |f|
f.inputs "Group" do
f.input :serie
f.input :name
end
f.actions
end
end
Any other suggestion on how to achieve my goal (specifying exactly the serie related to the unit) will be appreciated.
Try the following:
This code assumes that a Serie always have a Unit associated. It will raise an error if not. Use the following if you want to show the unit name only if it exists: