Skip to content

Instantly share code, notes, and snippets.

@workmad3
Forked from kracekumar/online_exam.rb
Created April 19, 2011 09:17
Show Gist options
  • Save workmad3/927051 to your computer and use it in GitHub Desktop.
Save workmad3/927051 to your computer and use it in GitHub Desktop.
#controller
def add_new_chapter
@chapter=Chapter.new
@user=current_user
@subjects=[]
@subject_final=[[]]
count=0
if @user.admin?
@subjects=Subject.all(:select=>'id,name,batch_id')
puts "#{@subjects}"
@subjects.each do |t|
@subjects_all=Batch.find(t.batch_id,:select=>'name')
@subject_final[count]['id']=t.id.to_i
@subject_final[count]['name']="#{@subject_all.name} #{t.name}"
count+=1
end
elsif @user.employee
@employee=Employee.find_by_employee_number(@user.username)
@subjects=EmployeesSubject.find_by_employee_id(@employee.id,:select=>'subject_id')
@subjects.each do |t|
@subjects_all=Batch.find(t.subject_id,:select=>'name')
@subject_final[count]['id']=t.id.to_i
@subject_final[count]['name']="#{@subject_all.name} #{t.name}"
count+=1
end
else
end
respond_to do |format|
format.js { render :action =>'new_chapter' }
end
#error
Batch Columns (0.6ms) SHOW FIELDS FROM `batches`
Batch Load (0.1ms) SELECT name FROM `batches` WHERE (`batches`.`id` = 2)
TypeError (can't convert String into Integer):
app/controllers/online_exam_controller.rb:57:in `[]='
app/controllers/online_exam_controller.rb:57:in `add_new_chapter'
app/controllers/online_exam_controller.rb:55:in `each'
app/controllers/online_exam_controller.rb:55:in `add_new_chapter'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment