ActiveRecord relationships..

Hi, I'm building my own homepage with this wonderfull "new" framework,
so far all has been very smooth until now.

I have a table (MySQL MyISAM) called "pages", which hold an id, title
and some content, now, I'm trying to make a "page" able to hold another
page by giving each "page"-row a "page_id" column, this clearly wont
work. My experience with table relations is quite limited. Any ideas
how I would solve this as simple and cleanly as possible?

I tried this in the model:

class Pages < ActiveRecord::Base
has_many :pages
end

But when using the above and trying to do:

page.pages.title

in the view I get:

"../active_support/dependencies.rb:100:in `const_missing': uninitialized constant Page"

Using page.page just gives me an "undefined method" error.

Thanks in advance

Hmm yeah, Its looking like that is what I'll have to do.. My idea was
to have a self-relationship easily allowing infinite levels of child
objects or something like that.. but I can't figure out a way to do
that.

Has anyone else got any clues?

Sounds like you want to use acts_as_tree.

http://ar.rubyonrails.com/classes/ActiveRecord/Acts/Tree/ClassMethods.html

-Ezra

Ezra Zygmuntowicz wrote: