hi there, i'm very new in ruby. i need to solve this asap. im out of idea already. please help me. thank u.
[code=]def egradebook end
def monthlytest #will find all record of person wif id of the current user (teacher) login @teachersubjects = Teachersubject.find(:all, :conditions => ["user_id = ?", session[:user_id]]) end
def monthlytestadd #here will list all student in class which has teacher of id 1001 @hello = Teachersubject.find(params[:id]) @students = Student.find(:all, :conditions => ["class1_id = ?", @hello.class1_id]) end
def addmark #Problem. now, the params[:id] has become class_id, so i cant take the teacher data (subject, year, semester) to be save in new gradebook record @teachersubject = Teachersubject.find(params[:id]) @students = Student.find(:all) @gradebook = Gradebook.new(params[:gradebook]) @gradebook.user_id = session[:user_id] @gradebook.subject_id = @teachersubject.subject_id #this part got prob @gradebook.year = @teachersubject.year #this part got prob @gradebook.semester = teachersubject.semester #this part got prob @gradebook.class1_id = params[:id] #and maybe need to change this part also? @gradebook.monthly = "yes" if @gradebook.save flash[:notice] = 'Student Mark Successfully Added.' redirect_to :action => 'monthlytest' else flash[:notice] = 'Error, Please Login' render :action => 'login' end end[/code]
i tried something like this which i think it could find the teacher's subject already but it turned error.
[code=]def addmark params['id'] = session[:user_id] @students = Student.find(:all) @teachersubject = Teachersubject.find(params[:id]) @gradebook = Gradebook.new(params[:gradebook]) @gradebook.user_id = session[:user_id] @gradebook.subject_id = @teachersubject.subject.id @gradebook.year = @teachersubject.year @gradebook.semester = @teachersubject.semester @gradebook.class1_id = @teachersubject.class1_id @gradebook.monthly = "yes" if @gradebook.save flash[:notice] = 'Student Mark Successfully Added.' redirect_to :action => 'monthlytest' else flash[:notice] = 'Error, Please Login' render :action => 'login' end end[/code] here's the error : ActiveRecord::RecordNotFound in AdminController#addmark Couldn't find Teachersubject with ID=1003
i want to get teacher's data from table teachersubject which consist of user_id, subject_id, class1_id, semester, year. but i dunno how to get those. maybe my params is wrong. 1003 is the teacher user_id
here are the data in the teachersubject table id -- subject_id -- user_id -- class1_id -- year -- semester 1 ----- 2 --------- 1003 --------- 1 ------ 2008 ----- 1 2 ----- 3 --------- 1003 --------- 2 ------ 2008 ----- 1
please give some ideas for me to solve this asap, thanks