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.
Justin W. (Guest)
on 2005-12-15 23: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.
Robert (Guest)
on 2005-12-15 23:38
(Received via mailing list)
Check out render()

E.g.

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




Rob
Justin W. (Guest)
on 2005-12-15 23: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 W.                             removed_email_address@domain.invalid
work: www.maczealots.com      play: www.carpeaqua.com
Phillip H. (Guest)
on 2005-12-15 23:48
(Received via mailing list)
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.
removed_email_address@domain.invalid
Josh C. (Guest)
on 2005-12-15 23:51
(Received via mailing list)
On 12/15/05, Justin W. <removed_email_address@domain.invalid> 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!
Ezra Z. (Guest)
on 2005-12-16 00:24
(Received via mailing list)
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
> removed_email_address@domain.invalid
> http://lists.rubyonrails.org/mailman/listinfo/rails

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid
Andreas S. (Guest)
on 2005-12-16 00:35
Phillip H. wrote:

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

Or just File.read('path').
Phillip H. (Guest)
on 2005-12-16 00: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 H.
removed_email_address@domain.invalid
This topic is locked and can not be replied to.