Skip to content

Instantly share code, notes, and snippets.

@kracekumar
Created April 19, 2011 13:10
Show Gist options
  • Save kracekumar/927559 to your computer and use it in GitHub Desktop.
Save kracekumar/927559 to your computer and use it in GitHub Desktop.
>> @subjects.each {
?> |t|
?> puts t.name
>> }
MATHS
maths
=> [#<Subject id: 9, name: "MATHS", batch_id: 2>, #<Subject id: 10, name: "maths", batch_id: 3>]
>> @subjects.each { |t|
?> @subjects_all=Batch.find(t.batch_id,:select=>'name')
>> @subject_final.map{|id| t.id.to_i}
>> @subject_final.map{|name| "#{@subject_all[:name]} #{t.name}" }
>> }
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[]
from (irb):31
from (irb):31:in `map'
from (irb):31
from (irb):28:in `each'
from (irb):28
>>
>> Batch.all
=> [#<Batch id: 2, name: "11 A Bio group", course_id: 2, start_date: "2011-04-15 00:00:00", end_date: "2012-04-15 00:00:00", is_active: true, is_deleted: false>, #<Batch id: 3, name: "9A 2011", course_id: 3, start_date: "2011-04-15 00:00:00", end_date: "2012-04-15 00:00:00", is_active: true, is_deleted: false>, #<Batch id: 4, name: "b", course_id: 2, start_date: "2011-04-16 00:00:00", end_date: "2012-04-16 00:00:00", is_active: true, is_deleted: false>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment