我很难理解如何将现有对象(类型为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是错误的,但我真的不知道它们应该是什么?我只想让用户填写他的电子邮件地址(对应于现有人员)并将用户注册为此事件的服务员。我如何做到这一点?