If I have this relationship how would I add to my view so that when I create a student I am given a textbox where I can add multiple courses for the new student?
class Student < ActiveRecord::Base
has_and_belongs_to_many :courses
end
class Course < ActiveRecord::Base
has_and_belongs_to_many :students
end
<%= form_for(@student) do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name%><br />
<%= f.label :description %><br />
<%= f.text_field :description %><br />
<%= f.submit %><br />
<% end %>
I recommend refactoring your models as follows:
and using RyanB’s
nested_formgem: https://github.com/ryanb/nested_form