Okay so I have a Courses, students, and registrations table. I allow the student to login and their info is stored in a session variable.they can search for courses, choose ones they want which puts the course_id into a session variable. then after they put the courses in a chosen_courses page, they can click the register button to register them for the courses. This is supposed to take the course_id from the session[:course] and the student_id from the session[:student_id] and put them into one table called registrations. The course_id is a set and i know that I am supposed to loop through each course_id and add it to the table but I am not able to. I have posted my controller below and here are the files THE FILES ARE HERE!!!!
HERE IS THE CONTROLLER WITH CODE THAT PUTS COURSE_ID AND STUDENT_ID IN DATABASE FROM SESSIONS:
def show
@register = Registration.new
while session[:course].course_id != nill do
@register.student_id = session[:student_id].student_id
@register.course_id = session[:course].course_id
end
@register.save
end
HERE IS THE VIEW THAT DISPLAYS THE DATA FROM THE registrations database:
<% @register.each do |register| %>
<tr>
<td><%= register.student_id %></td>
<td><%= register.course_id %></td>
</tr>
<% end %>
Any help is appreciated.
You can’t put models in your
sessionso you can’t access them like that. You need to load in anything you need based on theidstashed in there.Here’s what I think you’re shooting for:
Be sure to save only the course ID in the session and not the course itself.