Forum: Ruby on Rails PHP include() Type Functionality in Ruby/Rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3e76dc0a1f865175238d6b27f6580eff?d=identicon&s=25 Justin Williams (Guest)
on 2005-12-15 22:29
(Received via mailing list)
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.
C618e1d9ffa1bd1a6b6edc8ad4edec63?d=identicon&s=25 Robert (Guest)
on 2005-12-15 22:38
(Received via mailing list)
Check out render()

E.g.

render :partial => 'post'  # includes "_post.rhtml"




Rob
3e76dc0a1f865175238d6b27f6580eff?d=identicon&s=25 Justin Williams (Guest)
on 2005-12-15 22:45
(Received via mailing list)
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 Williams                             justin@carpeaqua.com
work: www.maczealots.com      play: www.carpeaqua.com
01d7a451018ac15518f425078ef00c40?d=identicon&s=25 Phillip Hutchings (Guest)
on 2005-12-15 22:48
(Received via mailing list)
On 16/12/2005, at 10:42 AM, Justin Williams 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 Hutchings
phillip.hutchings@sitharus.com
8c7a98649cdbbdf39eeed17ca9bdbbd3?d=identicon&s=25 Josh Charles (Guest)
on 2005-12-15 22:51
(Received via mailing list)
On 12/15/05, Justin Williams <justin@carpeaqua.com> 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!
8e44c65ac5b896da534ef2440121c953?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2005-12-15 23:24
(Received via mailing list)
On Dec 15, 2005, at 1:42 PM, Justin Williams 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
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Zygmuntowicz
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
ezra@yakima-herald.com
3a83969376c805ef5b6042191fdb0ff3?d=identicon&s=25 Andreas S. (andreas)
on 2005-12-15 23:35
Phillip Hutchings wrote:

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

Or just File.read('path').
01d7a451018ac15518f425078ef00c40?d=identicon&s=25 Phillip Hutchings (Guest)
on 2005-12-15 23:43
(Received via mailing list)
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 ;)

--
Phillip Hutchings
phillip.hutchings@sitharus.com
This topic is locked and can not be replied to.