views:

62

answers:

1

One of the components I need for an application I am working on is very similar to a CMS. Whereas I allow a user to write their own HTML.

The concept consists of custom tags and blocks.

For example. What i need to do is combine the following at runtime.

<div id="products">
 <module type="products" display="5" />
</div>

<!-- then a block-->

<div class="product" id="product-%[product_id]">
 <img src="%[product_image]" /><br />
 <span class="title"><a href="%[product_url]">%[product_title]</a</span>
</div>

In PHP i would use output buffering for this.

I don't need the nitty gritty of how to do every piece of this just, how can I output a page using this concept (coming from a database) instead of using the built in rails view.

A: 

If I understand your question correctly, you want to know how to render a string. This is straight out of Rails docs:

  # Renders the clear text "hello world" with status code 200
  render :text => "hello world!"

  # Renders the clear text "Explosion!"  with status code 500
  render :text => "Explosion!", :status => 500

  # Renders the clear text "Hi there!" within the current active layout (if one exists)
  render :text => "Hi there!", :layout => true

  # Renders the clear text "Hi there!" within the layout
  # placed in "app/views/layouts/special.r(html|xml)"
  render :text => "Hi there!", :layout => "special"
mtyaka