# Hierarchical pages content

**URL:** <https://www.ruby-forum.com/t/hierarchical-pages-content/88168>\
**Category:** Rails\
**Created:** [March 8, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/hierarchical-pages-content/88168 "2007-03-08T17:07:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [March 8, 2007, 5:07pm UTC](https://www.ruby-forum.com/t/hierarchical-pages-content/88168/1 "2007-03-08T17:07:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![johanatan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@johanatan](https://www.ruby-forum.com/u/johanatan)\
**Post date:** [March 9, 2007, 4:16am UTC](https://www.ruby-forum.com/t/hierarchical-pages-content/88168/2 "2007-03-09T04:16:57Z")

</div>

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)?
