PHP include() Type Functionality in Ruby/Rails

Greetings,

I am working on extending a new part of our site to use Ruby on
Rails, and have several portions of the site that is included in
external files. The rest of the site is built on top of MovableType
and uses PHP Includes to reference the external files.

Is there similar functionality in Ruby or Rails that I can use so I
don’t have to update excess content in two different locations?

Thanks.

Check out render()

E.g.

render :partial => ‘post’ # includes “_post.rhtml”

Rob

yes. but will render() parse a file that is not built into the actual
Rails application?

For instance, in PHP I have this line in my

<?php @include ("$document_root" . "movable-type/includes/ footer.php"); ?>

I need to have an equivalent in Rails. From what the documentation
says about render() its only for files that are within the actual
rails application itself: these files I need to include are not.

Thanks.


Justin W. [email protected]
work: www.maczealots.com play: www.carpeaqua.com

On 16/12/2005, at 10:42 AM, Justin W. wrote:

For instance, in PHP I have this line in my

<?php @include ("$document_root" . "movable-type/includes/ footer.php"); ?>

I need to have an equivalent in Rails. From what the
documentation says about render() its only for files that are
within the actual rails application itself: these files I need to
include are not.

erb templates allow full Ruby code.

<%= File.open(’/path/to/my/file’) do |file|
file.read
end
%>


Phillip H.
[email protected]

On 12/15/05, Justin W. [email protected] wrote:

I need to have an equivalent in Rails. From what the documentation
says about render() its only for files that are within the actual
rails application itself: these files I need to include are not.

Where are your files located? Ruby has a “require” function that
works somewhat like you are saying.

For instance, if you have the PDF::Writer library installed, and you
want to use it in a controller, you just put:

require ‘pdf/writer’

at the beginning of the file. Works like a charm!

On Dec 15, 2005, at 1:42 PM, Justin W. wrote:

yes. but will render() parse a file that is not built into the
actual Rails application?

For instance, in PHP I have this line in my

<?php @include ("$document_root" . "movable-type/includes/ footer.php"); ?>
<%= render :file => "/home/users/foobar/template.rhtml %>

With that you will be able to render an rhtml template that is
anywhere on the computer.

Cheers-
-Ezra

work: www.maczealots.com play: www.carpeaqua.com

external files. The rest of the site is built on top of


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
[email protected]

On 16/12/2005, at 11:35 AM, Andreas S. wrote:

Or just File.read(‘path’).

Um. Yes. Duh. I’ve been coding in PHP all morning, gotta keep a roof
over my head and everything. It’s just so mind numbing :wink:


Phillip H.
[email protected]

Phillip H. wrote:

<%= File.open(’/path/to/my/file’) do |file|
file.read
end
%>

Or just File.read(‘path’).