0
select 태그를 사용하여 부모 중 여러 중첩 된 자식을 저장하려고합니다. 레일 - 여러 개의 중첩 된 특성
이
내가Couldn't find all UserLocations with IDs (1, 2) (found 0 results, but was looking for 2)
찾고 있어요 오류입니다 I가 Rails 4
및 Devise
에서 다음 설정 :
사용자
class User < ActiveRecord::Base
has_many :user_locations
accepts_nested_attributes_for :user_locations, :allow_destroy => true
end
UserLocation (봐라 선택한 UserLocations
을 저장하려고 할 때 사용자가 가지고있는 양이온)
class UserLocation < ActiveRecord::Base
belongs_to :user
belongs_to :location
end
위치 (사용자에 따라 선택할 수있는 위치의 미리 정의 된 목록) 그러나
class Location < ActiveRecord::Base
has_many :user_locations
has_many :users, through: :user_locations
end
, 그들은 저장되지 않습니다 .
레일 선택 태그 (여러 항목을 선택할 수 있습니다)
<%= f.select :user_location_ids, options_for_select(Location.all.collect { |l| [ l.name, l.id ] }, @user.user_locations.collect{ |l| l.id }), {}, { multiple: true } %>
내가