Includes: The Ruby Way?

I was wondering if anyone had an opinion on how to do file includes in
RoR. I am currently doing it with JavaScript.

I am building a CMS for a dynamic website. I want a tool that lets
non-programmers build a website by filling out some forms, making some
choices (templates, images, etc..), and previewing the page before
publishing it.

The tool should take the info from the CMS forms and populate modules
(mini web pages) that will then make-up the website. I plan on building
the final webpage by including the modules in the template.

So anyways, what's the Ruby way to do includes?

Code and pointers to tutorials are always helpful.

Thanks in Advance -- K

The very same thing that bothers me in ruby. We can do this “include” very easily in PHP. And I can’t seem to find the same method to “include” in ruby.

As for rails, maybe you can try using render_component, like me. I use render_component to include modules (as in joomla) in pages. Or using helpers to generate components and modules (as in joomla).

I admit that this seem kind of messy… But I can’t think of any other way right now… ~_~

render :partial => “path/to/partial”

Remember, partials can take in variables as well, or can simply act like includes and use variables declared in the request scope (@ variables)

The very same thing that bothers me in ruby. We can do this "include" very
easily in PHP. And I can't seem to find the same method to "include" in

Bear in mind that PHP's include functionality has two purposes - 1)
including other source code - the Ruby equivalent of this is require.
2) Including templates within templates (like server-side includes) -
the reason PHP makes this easy is because it was originally designed as
a templating language. Ruby wasn't therefore the whole concept of SSIs
in Ruby wouldn't make sense. In Rails, this is what partials are for.

Thanks everyone. Partials work great.


I need to include an outside resource. Is it possible to do with render
or is there something else that will work?

<%= render :partial => "" %>

There are two plausible ways to go about this:

You'll need to require 'open-uri' for this first one, which has the Rails
app connect to and read from the URL:

<%= open("", &:read) %>

The other way is to use an HTML iframe (and you'll need to check the syntax
on that). This makes the client browser request the URL on its own:

<iframe src="" />