방 모델과 사람 모델이 있습니다.accepts_nested_attributes_for 및 select 태그
방은 많은 사람을 가질 수 있으며 사람은 한 방을 가질 수 있습니다. 방 생성 화면에서
나는 '링크'N이 새로운 방 에 사람이 그래서 모든 사람들의 목록이 포함 select 태그의 변수 양을 갖고 싶어나는 방법을 모른다 할 수 select 태그를 빌드하십시오.
사람이
감사를 도울 수
... I/새로운 형태의 다음과 같은 협회가class Room < ActiveRecord::Base
has_many :people
accepts_nested_attributes_for :people
end
class Person < ActiveRecord::Base
belongs_to :room
end
내가 방을 구축 할 부분을 사용했습니다
<% form_for(@room) do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :date %><br />
<%= f.date_select :date %>
</p>
<% f.fields_for :people do |builder| %>
<p>
<%= builder.label :person_id, "Person" %><br />
<%= select 'room', 'people', Person.all.collect{|person| [person.name, person.id]}%>
</p>
<% end %>
<p>
<%= f.label :comment %><br />
<%= f.text_area :comment %>
</p>
<p>
<%= f.submit 'Create' %>
</p>
<% end %>