You could build the number of students you need to have fields for in your controller new
action like follows:
# app/controllers/projects_controller.rb
def new
@project = Project.new
3.times do
student = @project.students.build
end
end
This will build three students under project instance.
Then update your view's form_for
declaration as follows:
# app/views/projects/new.html.erb
<%= form_for @project, url: projects_path do |f| %>
<p>
<%= f.label :name %>
<%= f.text_field :name %>
</p>
<p>
<%= f.label :lecturer %>
<%= f.text_field :lecturer %>
</p>
<p>
<%= f.fields_for :students do |s| %>
<%= s.label :name %>
<%= s.text_field :name %>
<% end %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>