Forum: Ruby on Rails hierarchical pages content

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Cd804cfeeea508f6bf2f5487c9ef4aed?d=identicon&s=25 Jonathan Linowes (Guest)
on 2007-03-08 17:07
(Received via mailing list)
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.

Cd804cfeeea508f6bf2f5487c9ef4aed?d=identicon&s=25 linoj (Guest)
on 2007-03-09 04:16
(Received via mailing list)
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|

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

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

    unless @page.modelmethod.nil?
      data_model, data_method, @data_partial =
      unless data_model.nil? || data_method.nil? || @data_partial.nil?
        @data = Object.const_get(data_model).send(data_method)

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
    <% for director in directors_list %>

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)?
This topic is locked and can not be replied to.