我有一个集合选择方法,如下所示:
<%= 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 %>
这样可以正常工作,但是,在选择所有多个对象后,如果用户在提交表单时失败了任何验证并且表单重新加载,则会丢失用户之前点击的所有值。
然后用户必须重新选择所有内容。所以,我想知道是否有办法帮助保存实例。我环顾四周,没有遇到任何解决方案。
感谢任何帮助!
被修改 调用此表单的方法如下:
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