On 6 November 2010 07:55, Zack <[email protected]> wrote: > Where in the Student#Create Controller i am doing > > �...@teacher = Teacher.where(['id=?', > session[:logged_teacher].techerId]).first > �...@student = @teacher.students.build(params[:student]) > > however when I try to create the user and save in the database the > record is being created in the student table however the Join Table is > not being populated. Am I doing something wrong here? am I missing > out on something?
Do you save the @teacher after you've built the @student? Your code all looks okay at first glance and seems to match what the docs say: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html But there is possible typo in there: @teacher = Teacher.where(['id=?', session[:logged_teacher].techerId]).first ...should that be "teacher_id" rather than "techerId"? and you could just do @teacher = Teacher.find(session[:logged_teacher].techerId) As and aside, I'd recommend *not* saving whole Teacher objects in the session - rather, just save their ID and retrieve them again from the DB on the next request. I've seen problems in applications where one too many objects gets saved in the session for the available space, and much confusion ensues! :-) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

