I have this select which works fine, but default the select is empty and doesn’t show the selected value (which is filled correctly):
<%= f.select(:relationgroup, options_for_select(@relationgroups), { :selected => @relation.relationgroup, :include_blank => true}) %>
Any idea why? Thanks!
Try it that way:
Not sure, but maybe it’ll work better.
Anyway, assuming
Relationgroupis some model withidandname(or any other attribute that you want to be visible in select options) attributes, and you’re using defaultrelationgroup_idforeign key in your model you’d better construct your select like that:It’ll choose selected value based on
object.relationgroup_idwhereobjectis the model you’re building form for. See docs for more information.