I have two models, subject and page. I created a one-to-many association between them.
class Subject < ActiveRecord::Base
has_many :pages
attr_accessible :name
attr_accessible :position
attr_accessible :visible
attr_accessible :created_at
end
and
class Page < ActiveRecord::Base
belongs_to :subject
attr_accessible :subject_id
attr_accessible :name
attr_accessible :permalink
attr_accessible :position
attr_accessible :visible
attr_accessible :created_at
end
As mentioned above, I have two models, and I want to access all subject names which are in the Subject model to the page model/controller…
If you want to get all the subjects saved in a subject model use:
or to access a subjects associated with particular page: