hierarchical pages content

Hi, this is a design question

I've setup a micro-cms for my About pages etc using a "pages" table containing name, title, body, parent_id, position, and the model is setup as both acts_as_tree and acts_as_list. The pages table has the page content, and also is used to define the menus for the tree. This is working, so far so good.

Some of these pages might contain a list of items from another table, for example, Board of Directors, shown after the body text. One way I'm thinking to handle this is

add fields to pages for sub-content model, method name, and partial, and have the pages controller call the method and pass the data along to the display_page template (which calls the partial)

What do you think?

An alternative would be to add a controller/action for the other content and just use the page as a placeholder so it still shows in the menu. And add a url field to the page model (or even separate controller, action fields), thats used in the menu link.

linoj

hi, this is how I solved it:

lets say I have one model, "page" with a list of pages, and another model "director" with a list of company directors.

A page has a title, body, etc plus an optional field called "modelmethod", which expects a string in the format "Model|method| partial".

On the page that should contain the list of directors I enter the string "Director|get_list|directors_list", meaning for the Director model, use the get_list method to get a collection, and display it with the _directors_list.rhtml partial.

The Director model has a method:   def self.get_list     find(:all, :order => "position")   end

On the page controller, I parse the modelmethod string, call the method and pass the results (@data and @data_partial) to the view, as follows:

    unless @page.modelmethod.nil?       data_model, data_method, @data_partial = @page.modelmethod.split(/\s*\|\s*/)       unless data_model.nil? || data_method.nil? || @data_partial.nil?         @data = Object.const_get(data_model).send(data_method)       end     end

In the page view, i call the partial with the data

          <% unless @data.nil? %>             <%= render :partial => @data_partial, :object => @data %>           <% end %>

And the partial template, named _directors_list.rhtml displays the list     <% for director in directors_list %>         etc

Thus, now I can configure my "pages" through the admin gui to show content from other tables.

Is this cool? or is it a bad idea for some reason(s)?