Why is the first element always blank in my Rails multi-select, using an embedded array?

后端 未结 9 2388
我寻月下人不归
我寻月下人不归 2020-11-29 19:54

I\'m using Rails 3.2.0.rc2. I\'ve got a Model, in which I have a static Array which I\'m offering up through a form such that users may se

9条回答
  •  旧巷少年郎
    2020-11-29 20:18

    I fixed it using the params[:review][:staff_ids].delete("") in the controller before the update.

    In my view:

    = form_for @review do |f|
      = f.collection_select :staff_ids, @business.staff, :id, :full_name, {}, {multiple:true}
    = f.submit 'Submit Review'
    

    In my controller:

    class ReviewsController < ApplicationController
      def create
      ....
        params[:review][:staff_ids].delete("")
        @review.update_attribute(:staff_ids, params[:review][:staff_ids].join(","))
      ....
      end
    end
    

提交回复
热议问题