Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You'd have to do something like this:</p> <p>pages_controller.rb:</p> <pre><code>class PagesController &lt; ApplicationController prepend_view_path PageTemplate::Resolver.instance def render_page #Some logic to retrieve the @site &amp; @current_page records.... render :layout =&gt; @site.layout.path, :template =&gt; @current_page.template.path end . . . </code></pre> <p>models/page_template.rb:</p> <pre><code>class Resolver &lt; 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 =&gt; Mime[record.format], :updated_at =&gt; record.updated_at, :virtual_path =&gt; 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 </code></pre> <p>Of course this can be refactored quite a bit, but this is the general idea. Also you would need 1 or 2 database tables depending weather you prefer to store the templates and layouts separately or together with the following columns: title, body, path, format, locale, handler, partial</p> <p>Hope that helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload