Reputation: 3337
I have a field in one of my Rails forms that selects a "unit" and works fine initially. However when I go into the record the select defaults to another unit and not the one that was assigned, thus not retaining the value.
_form.html.erb
<%= f.select :unit_id, options_for_select(unit_select), {}, {:class => 'select'} %>
helper
def unit_select
Unit.all.map{|unit| unit.calls.empty? ? [unit.unit_name, unit.id] : ["#{unit.unit_name} (on call)", unit.id] }
end
The only thing I can think of is it's not retaining the value since the form field is using a map. I'm kind of newish to Rails and Ruby so I don't fully understand the constrains of my code yet.
Any help or suggestions is appreciated.
Upvotes: 0
Views: 183
Reputation: 3337
I was able to solve this by using options_for_select :selected => @call.unit.id
It then retained the previous selected value.
Upvotes: 1