Вы должны сделать что-то вроде этого:
pages_controller.rb:
class PagesController < ApplicationController
prepend_view_path PageTemplate::Resolver.instance
def render_page
#Some logic to retrieve the @site & @current_page records....
render :layout => @site.layout.path, :template => @current_page.template.path
end
.
.
.
models / page_template.rb:
class Resolver < ActionView::Resolver
require "singleton"
include Singleton
def find_templates(name, prefix, partial, details)
if prefix.empty?
#If this is not a layout, look it up in the views table and pass that record to the init function
initialize_template('Template', record)
end
elsif prefix === 'layouts'
#If this is a layout, look it up in the layouts table and pass that record to the init function
initialize_template('Layout', record)
end
end
end
# Initialize an ActionView::Template object based on the record found.
def initialize_template(type, record)
source = record.body
identifier = "#{type} - #{record.id} - #{record.path.inspect}"
handler = ActionView::Template.registered_template_handler(record.handler)
details = {
:format => Mime[record.format],
:updated_at => record.updated_at,
:virtual_path => virtual_path(record.path, record.partial)
}
ActionView::Template.new(source, identifier, handler, details)
end
# Make paths as "users/user" become "users/_user" for partials.
def virtual_path(path, partial)
return path unless partial
if index = path.rindex("/")
path.insert(index + 1, "_")
else
"_#{path}"
end
end
end
Конечно, этоможно немного реорганизовать, но это общая идея.Также вам понадобится 1 или 2 таблицы базы данных в зависимости от погоды, в которой вы предпочитаете хранить шаблоны и макеты отдельно или вместе со следующими столбцами: заголовок, тело, путь, формат, языковой стандарт, обработчик, частичный
Надеюсь, это поможет!