accept nested attributes for has_many relationship

后端 未结 3 836
谎友^
谎友^ 2020-12-19 16:40

Below are my two model classes

class Patient < ActiveRecord::Base
  belongs_to :user, :dependent => :destroy
  has_many :enrollments, :dependent =>          


        
3条回答
  •  没有蜡笔的小新
    2020-12-19 17:05

    Instead of

    :client_id
    

    in the collection_select, try

    "client_id[]"
    

    The second form specifies that you're accepting an array of IDs for the attribute rather than a single one.

    Here's a good resource on the usage of the select helpers in forms: http://shiningthrough.co.uk/Select-helper-methods-in-Ruby-on-Rails

提交回复
热议问题