remove a blank option of select field that was generated by SimpleForm

前端 未结 3 2048
闹比i
闹比i 2021-02-03 17:48

I have this piece of code:

= f.input :category, :as => :select, :label => false, :collection => Choices[\"Categories\"]

Choices[\"Cate

3条回答
  •  北恋
    北恋 (楼主)
    2021-02-03 18:14

    or you can customize call back action in your model to remove any empty string in the array parameter, assuming a parameter with the name "types":

    before_validation :remove_empty_string
    
    def remove_empty_string
      types.reject! { |l| l.empty? }
    end
    

提交回复
热议问题