I have a bunch of html files with partial page content. I''d like to be
able to include the content of these files in my RoR views without
having to change or rename them.
In PHP I''d simply use
include("file.html");
What is the RoR equivalent of this? render_file insists on it being an
rhtml template, and render_partial requires me to rename the file.
Ideally, I could put the files in a separate dir, e.g. in /public/html/
Tia!
--
Posted via http://www.ruby-forum.com/.
Easiest way is to simply rename them.
Other then that though you could simple open the file and spit the
results manually. So, a simple helper function:
def include_page(file_name)
result = ""
File.open(file_name, "r") { |f| result << f.read }
result
end
*note, not tested for typos or accuracy :)
This should work, and you can add in a defualt directory to look in
and things to make it a little easier to work with.
-Nick
On 2/21/06, Filip Godsmurf <krommenaas@gmail.com>
wrote:> I have a bunch of html files with partial page content. I''d like
to be
> able to include the content of these files in my RoR views without
> having to change or rename them.
>
> In PHP I''d simply use
> include("file.html");
>
> What is the RoR equivalent of this? render_file insists on it being an
> rhtml template, and render_partial requires me to rename the file.
>
> Ideally, I could put the files in a separate dir, e.g. in /public/html/
>
> Tia!
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> -----Original Message----- > From: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Nick Stuart > Sent: Tuesday, February 21, 2006 12:32 PM > To: rails@lists.rubyonrails.org > Subject: Re: [Rails] how to include an html file? > > > Easiest way is to simply rename them. > > Other then that though you could simple open the file and > spit the results manually. So, a simple helper function: > > def include_page(file_name) > result = "" > File.open(file_name, "r") { |f| result << f.read } > result > endThat can be shortened to: def include_page(file_name) IO.read(file_name) end Regards, Dan
Of course it can! :) Thanks for that, there seems to always be a ''shorter'' way in ruby! On 2/21/06, Berger, Daniel <Daniel.Berger@qwest.com> wrote:> > -----Original Message----- > > From: rails-bounces@lists.rubyonrails.org > > [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Nick Stuart > > Sent: Tuesday, February 21, 2006 12:32 PM > > To: rails@lists.rubyonrails.org > > Subject: Re: [Rails] how to include an html file? > > > > > > Easiest way is to simply rename them. > > > > Other then that though you could simple open the file and > > spit the results manually. So, a simple helper function: > > > > def include_page(file_name) > > result = "" > > File.open(file_name, "r") { |f| result << f.read } > > result > > end > > That can be shortened to: > > def include_page(file_name) > IO.read(file_name) > end > > Regards, > > Dan > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Thanx guys! -- Posted via http://www.ruby-forum.com/.
OR: <%= render :file => ''/absolute/full/path/to/file'' %> And that will interpret any erb thats in the file as well. Cheers- -Ezra On Feb 21, 2006, at 12:01 PM, Filip Godsmurf wrote:> Thanx guys! > > -- > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >