I have a collection select method as shown:
<%= fields_for :deal_venue do |dv| %>
<div class = "field form-textarea clearfix">
<%= dv.label "Select Venues" %><br />
<%= collection_select(:venues, :id, @all_venues, :id, :name, {}, {:multiple => true, :prompt => true}) %>
</div>
<% end %>
This is working fine, however, after selecting all the multiple objects, if a user fails any validation when submitting the form and the form reloads, it loses all the values previously clicked by the user.
The user then has to re-select everything. So, I was wondering if there is a way to help save the instance. I looked around and did not come across any solutions.
Any help is appreciated!
Edited The method calling this form is as follows:
def create
@deal = Merchant.find(merchant_id).deals.new(deal_params)
# Get all venue locations from this merchant
@locations = Venue.pluck(:neighbourhood)
# For drop down form
@all_venues = MerchantService.get_all_venues(merchant_id)
if @deal.save
flash[:success] = "Deal successfully created!"
redirect_to @deal
else
flash[:error] = "Failed to create deal!"
render 'new'
end
end