Привет, у меня есть следующая модель:
Boys have_many relationships
Girls have_many relationships
Relationship belongs to boy
Relationship belongs to girl
Пока у меня есть следующее:
def create
@boy = Boy.find(current_boy.id)
@relationship = @boy.relationships.create(:relationship)
redirect_to boy_path(@boy)
end
Это мой home.html.erb
<%= form_for([@boy, @boy.relationships.build]) do |f| %>
<div class="field">
<%= f.label :points %><br />
<%= f.number_field :points %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
Файл миграции:
def change
create_table :relationships do |t|
t.integer :points
t.references :boy
t.references :girl
t.timestamps
end
add_index :relationships, :boy_id
add_index :relationships, :girl_id
end
Так что отношения имеют «точки». Когда я отправляю форму, я хочу указать адрес электронной почты девушки.
Как мне поместить это как часть формы и исправить метод create, чтобы при отправке этой формы я создавал отношения между мальчиком и девочкой?
Большое спасибо.