What is the Ruby on Rails equivalent to php includes?

If I was to include a file (such as in a template) in php to use
across a large number of pages, I would write this:
<?php include ('navigation.html'); ?>

In turn, every time I used this code, it would “include” (or better
put, display) the content of navigation.html in the browser.

I can’t figure out how to do this is Rails. When building my layouts,
how can I include a file like this, like I would in PHP. I have files
I’d like to include remotely, but not sure how to get this done.

Any ideas?

render :partial => 'foo/bar'

I tried that, with something like this:

<%= render :partial => ‘http://example.com/navigation.html’ %>

And I got the "We're sorry, but something went wrong." page from my
app.

I am 100% positive the server I'm trying to include the file from
allows files to re used remotely.

The partial file should be local to the Rails app.

You can’t do that. render works only with files local to your app.

Jason

Right. That helps if the file I am using is locally. But what do I do
if that file is from another server?

OK ... so is there another way to do it without using render?

Surely this isn't something that PHP can do that Rails can't.

OK ... so is there another way to do it without using render?

Surely this isn't something that PHP can do that Rails can't.

This is a terrible idea. But hey, here, have a loaded gun:

<%= open("http://example.com/navigation.html").read %>

~ j.

If there's some sort of risk, please inform.

Not that it matters, that didn't work either.

I should clarify.

1. I control both servers that I'm working with, so the security risk
is practically nil.
2. The app is very small. Any performance hits I'd take by including a
remote file is acceptable.

That said, still don't have a fix.

Thanx.

Eric

Eric Gruber wrote:

If there's some sort of risk, please inform.

I agree, this is a terrible idea from both performance and architectural
perspectives. Why do you want your navbar to live on another server?

Not that it matters, that didn't work either.

What happened when you tried the open().read solution? Just saying that
it didn't work isn't that helpful.

Best,

What happened was I got the "We're sorry, but something went wrong."
page from my
app.

I would prefer it all to be on one server, but the company I'm trying
to do this for has many different projects, using different languages
on two different servers. I'd rather not include a copy on the second
server, so if I have to make a change to that one file (remember kids,
don't repeat yourself!) I have to only do it once on one server.

What happened was I got the "We're sorry, but something went wrong."
page from my
app.

I would prefer it all to be on one server, but the company I'm trying
to do this for has many different projects, using different languages
on two different servers. I'd rather not include a copy on the second
server, so if I have to make a change to that one file (remember kids,
don't repeat yourself!) I have to only do it once on one server.

You must require 'open-uri' to be able to open URLS. For example:

open("http://example.com/").read

Errno::ENOENT: No such file or directory - http://example.com/
        from (irb):2:in `initialize'
        from (irb):2:in `open'
        from (irb):2

But if you require 'open-uri':

require 'open-uri'

=> true

open("http://example.com/").read

=> "<HTML>\r\n<HEAD>\r\n <TITLE>Example Web Page</TITLE>\r\n</HEAD> \r
\n<body> \r\n<p>You have reached this web page by
typing&quot;example.com&quot;,\r\n&quot;example.net&quot;,\r\n or
&quot;example.org&quot; into your web browser.</p>\r\n<p>These domain
names are reserved for use in documentation and are not available \r
\n for registration. See <a href="http://www.rfc-editor.org/rfc/
rfc2606.txt">RFC \r\n 2606</a>, Section 3.</p>\r\n</BODY>\r\n</HTML>\r
\n\r\n"

Right on, that worked for me. Thanx so much!

Mauricio Szabo wrote:

But if you require 'open-uri':

require 'open-uri'

=> true

open("http://example.com/").read

=> "<HTML>\r\n<HEAD>\r\n <TITLE>Example Web Page</TITLE>\r\n</HEAD> \r
\n<body> \r\n<p>You have reached this web page by
typing&quot;example.com&quot;,\r\n&quot;example.net&quot;,\r\n or
&quot;example.org&quot; into your web browser.</p>\r\n<p>These domain
names are reserved for use in documentation and are not available \r
\n for registration. See <a href="http://www.rfc-editor.org/rfc/
rfc2606.txt">RFC \r\n 2606</a>, Section 3.</p>\r\n</BODY>\r\n</HTML>\r
\n\r\n"

Wow! This is a bad idea. Including a full page inside another page just
makes my skin crawl. If I absolutely had to do something like this I
would maybe grab the page using open(...), but then strip out only the
contents inside the body tag and render that inside the final page.
Otherwise you'll never be able to get a clean validation anything using
that "navbar page."

And think of how b0rken the stats will be for the server hosting the
navbar.html. That's enough to make wanna vomit. *quiver*

I don't believe the OP ever said that it would be a full page that he
would be including. He is just trying to access partials from one of
his servers on another. Presumably some of the data for the remote
one is not accessible to the local one.

Colin