Y.A.N (yet another newbie)
Using rails, I have a 'students' controller and a 'contacts' controller and of course, a student model and contact model. contact belongs_to student and student has_many contacts. I have an index page of students that lists each student with the option to click "Add Contact" for each student. I'm losing it when I try to call the contacts' 'new' action and subsequently the "new" view for contacts. How/where do i initialize the student and/or contact so the contact knows the student_id. Right now, I'm passing the student to the new_contact_path but then I have to refer to the student_Id as params(:format) inside the contact controller in order to get it to work. this is obviously not the best way. Any ideas Pieces of code below:
ContactsController:
def new
@contact = Contact.new
@student = Student.find(params[:format])
end
students index:
<% @students.each do |student| %>
<tr>
<td><%= link_to 'Contacts', new_contact_path(student) %></td>
</tr>
<% end %>