Hi Dominic,
Ah – everything is much more clear now. What you’re describing is a
fairly core behavior of Rails. Associations are indeed the right way
to go here.
For example, say you have an extension called Ages, which you would
create with “script/generate extension Ages”. In the extension, you
have a model, AgeGroup (created with “script/generate extension_model
Ages AgeGroup”).
The create_table part of the migration for AgeGroup might look
something like (note that none of these examples have been tried yet,
so I may have minor syntax errors):
create_table do |t|
t.column :min, :integer
t.column :max, :integer
end
and the class might look like:
class AgeGroup < ActiveRecord::Base
has_many :pages
end
and somewhere else (either /app/models or /lib) have something like:
module PageExtension
belongs_to :age_group
end
Page.send(:include, AgePageExtension)
You should explicitly require this file in your age_extension.rb.
Of course, you’ll need a migration to alter pages to have an
:age_group_id column (and you’ll probably want an index on that too).
You’ll also need a controller for Admin-ing the age_groups table. It
should be simple CRUD operations, which other extensions cover pretty
well.
After you understand that, it’s time to move on to something a little
more complicated: To actually display the information, my
recommendation is to do something similar to the ArchivePages. Have
one page that lists all of the age groups with links to a child page
for each age group. The child pages would actually be a single
virtual page that gets the age-group specified in the URL. Although
code-blindness will hurt here, I recommend you look at
radiant/app/models/archive_page.rb,
radiant/app/models/archive_*_index_page.rb and
radiant/lib/archive_index_tags_and_methods.rb for an idea of what I’m
talking about.
The most important things are that ArchivePage overrides child_url
(the method responsible for making a url for a page’s child) and
find_by_url (the method responsible for returning a Page to render).
Also, tags are a good thing for dynamic content (such as a list of
pages for a certain age group).
Hope this helps,
Andrew