我很難理解如何將現有對象(類型爲person)添加到Ruby-on-Rails中的另一個表(事件)。我創建了表格人員和表格事件之間的多對多關係,但現在我不知道如何將現有人員添加到現有事件。這是我的模型:將現有人員添加到rails中的事件
人:
class Person < ApplicationRecord
has_many :messages
has_and_belongs_to_many :event
validates :name, presence: true
validates :email, presence: true
validates :birth, presence: true
end
事件:
<%= form_for([@event, @event.people.build]) do |f| %>
<p>
<%= f.label :email %><br>
<%= f.text_field :email %>
</p>
<p>
<%= f.submit %>
</p>
<%end%>
:
class Event < ApplicationRecord
has_many :messages
has_and_belongs_to_many :people
validates :title, presence: true
validates :description, presence: true
validates :minimum_age, presence: true
validates :maximum_age, presence: true
validates_numericality_of :maximum_age, :greater_than => :minimum_age
validates :start, presence: true
validates :end, presence: true
end
現在,我使用的是官方軌教程製作這種形式在事件的看法很明顯,form_for-parameters是錯誤的,但我真的不知道它們應該是什麼?我只想讓用戶填寫他的電子郵件地址(對應於現有人員)並將用戶註冊爲此事件的服務員。我如何做到這一點?