Php include() equivalent

Is there an equivelent ruby function that is similar or exactly the same
as the php include() function? I would like to be able to include a
header for my RoR web application that refers to a url. Thanks!

-Gilles

Gilles wrote:

Is there an equivelent ruby function that is similar or exactly the same
as the php include() function? I would like to be able to include a
header for my RoR web application that refers to a url. Thanks!

-Gilles

It’s not quite equivalent in rails, simply beacause in PHP all files are
view files and you may be including functionality, html output, or both.

But it sounds like what you need are partials or layouts.

Layouts:
Create a file called app/views/layouts/application.rhtml and stick your
application layout there. Should look like an expanded form of
something like this:

Foo <%= yield %>

Now the content rendered by your actions will be inserted into the <%=
yield %> tag, for all pages, all the time.

Partials:
create a view file called app/views/some_controller/_header.rhtml with
whatever html/erb fragments you like and render it into your view with:

<%= render :partial => ‘header’ %>

Thanks for replying Alex. I understand the idea of layouts and partials
and have already been using them for several things within my RoR web
application. However, the problem is that I want to refer to html
outside of my layout or partial by referencing a URL. This might not be
entirely necessary, but while we’re on the topic, I wonder if Ruby is
capable of doing it.

-Gilles

Gilles wrote:

Thanks for replying Alex. I understand the idea of layouts and partials
and have already been using them for several things within my RoR web
application. However, the problem is that I want to refer to html
outside of my layout or partial by referencing a URL. This might not be
entirely necessary, but while we’re on the topic, I wonder if Ruby is
capable of doing it.

-Gilles

Ah, OK.

To get a page on another server, use open-uri or net/http. open-uri is
easier.

Learn to use it here:
http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/

You basically can download a page into an instance variable in your
controller (or model) and include in your view like any other instance
variable.