Get a collection through ActiveRecord for using with option_

Hello,

I am having some difficulties with ActiveRecord.

What I want to do is to get a collection of SubjectGroups for using
with option_groups_from_collection_for_select

My Code:

========================================
class Subject < ActiveRecord::Base
has_and_belongs_to_many :users
belongs_to :subject_group
end

class SubjectGroup < ActiveRecord::Base
has_many :subjects
end

@subjects= Subject.find(:all, :include => :subject_group)
@groups= SubjectGroup.find(:all, :include => :subjects)

The first find instruction runs just fine, the second gives me the
following error:

You have a nil object when you didn’t expect it!, The error occurred
while evaluating nil.loaded

I was expecting a SubjectGroup collection with all Subjects associated.

In both cases I saw the generated queries through logs and returns the
same query result.

Thank you for your attention,

Paulo A.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs