Ruby on Rails — multiple selection in f.select

前端 未结 5 516
故里飘歌
故里飘歌 2020-12-02 15:21

I have the following select box in my form:

Related Type:   <%= f.select(:TYPE, [[\'Type A\', \'Type A\'],
                                  [\'T         


        
5条回答
  •  离开以前
    2020-12-02 15:49

    HTML

    <%= form.select(:product_ids, Product.all.collect {|p| [ p.name, p.id ] }, 
                                                       { :prompt => "Please select"}, 
                                                       { :multiple => true, :size => 5  }) %>
    

    Controller

    @category = Category.new(category_params) 
    
    def category_params
        params.require(:category).permit(:name, product_ids: [])
    end
    

提交回复
热议问题