Skip to content

Instantly share code, notes, and snippets.

@tbuehlmann
Forked from kracekumar/console.rb
Created April 19, 2011 13:22
Show Gist options
  • Save tbuehlmann/927654 to your computer and use it in GitHub Desktop.
Save tbuehlmann/927654 to your computer and use it in GitHub Desktop.
@subject_all = []
@subjects.each do |subject|
@subject_all << [subject.id, subject.batch.name]
end
# Or with a hash:
#
# @subject_all = {}
#
# @subjects.each do |subject|
# @subject_all[subject.id] = subject.batch.name
# end
@kracekumar
Copy link

@subjects.each { |t|
?> @subjects_all=Batch.find(t.batch_id,:select=>'name').name

}
=> [#<Subject id: 9, name: "MATHS", batch_id: 2>, #<Subject id: 10, name: "maths", batch_id: 3>]
@subject_all.name
NoMethodError: undefined method name' for nil:NilClass from /var/lib/gems/1.8/gems/activesupport-2.3.9/lib/active_support/whiny_nil.rb:52:inmethod_missing'
from (irb):41
@subject_all[: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):42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment