# Source a javascript and stylesheet into rhtml file

**URL:** <https://www.ruby-forum.com/t/source-a-javascript-and-stylesheet-into-rhtml-file/114557>\
**Category:** Ruby\
**Created:** [September 15, 2007, 6:46am UTC](https://www.ruby-forum.com/t/source-a-javascript-and-stylesheet-into-rhtml-file/114557 "2007-09-15T06:46:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![2tcreative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/a3d4f5/32.png) [@2tcreative](https://www.ruby-forum.com/u/2tcreative)\
**Post date:** [September 15, 2007, 6:46am UTC](https://www.ruby-forum.com/t/source-a-javascript-and-stylesheet-into-rhtml-file/114557/1 "2007-09-15T06:46:57Z")

</div>

Hi all,

I’m trying to do a quick dump of a javascript and style sheet located in  
their respective /public directories into an rhtml file. I want to  
include the entire text of the file in my rhtml file. How do I do this  
quickly and efficiently? In PHP there’s readfile, but I can’t figure out  
an equivalent call in ruby.

Thanks so much in advance!

Tim

---

<div class="post-metadata">

**Author:** ![2tcreative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/a3d4f5/32.png) [@2tcreative](https://www.ruby-forum.com/u/2tcreative)\
**Post date:** [September 17, 2007, 1:25pm UTC](https://www.ruby-forum.com/t/source-a-javascript-and-stylesheet-into-rhtml-file/114557/2 "2007-09-17T13:25:16Z")

</div>

Tim Trampedach wrote in message ne\

> I’m trying to do a quick dump of a javascript and style sheet located in  
> their respective /public directories into an rhtml file.

\<%=h File.read(RAILS\_ROOT + ‘/public/javascript/my\_source.js’) %\>

This is half introductory Ruby and half introductory Rails, so one might  
consider reading a little of the excellent books on these subjects,  
offline,  
for a while!

---

<div class="post-metadata">

**Author:** ![2tcreative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/a3d4f5/32.png) [@2tcreative](https://www.ruby-forum.com/u/2tcreative)\
**Post date:** [September 25, 2007, 11:03pm UTC](https://www.ruby-forum.com/t/source-a-javascript-and-stylesheet-into-rhtml-file/114557/3 "2007-09-25T23:03:53Z")

</div>

On Sat, Sep 15, 2007 at 02:24:59PM +0900, James B. wrote:

> better, faster, information.  
> While Philip may have assumed that Tim was using Rails, there was  
> nothing  
> in the original post to indicate that Rails is involved. It’s just ERB  
> to  
> produce HTML (in this case with embedded JS and CSS), which comes up in  
> other contexts.

> James B.  
> –Greg

---

<div class="post-metadata">

**Author:** ![2tcreative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/a3d4f5/32.png) [@2tcreative](https://www.ruby-forum.com/u/2tcreative)\
**Post date:** [September 25, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/source-a-javascript-and-stylesheet-into-rhtml-file/114557/4 "2007-09-25T23:09:16Z")

</div>

Gregory S. wrote:

> While Philip may have assumed that Tim was using Rails, there was nothing  
> in the original post to indicate that Rails is involved. It’s just ERB to  
> produce HTML (in this case with embedded JS and CSS), which comes up in  
> other contexts.

Amazingly true.

My reply was to suggest a better place for Rails help if this was in  
fact part of a Rails matter.

–  
James B.

“I have the uncomfortable feeling that others are making a religion  
out of it, as if the conceptual problems of programming could be  
solved by a single trick, by a simple form of coding discipline!”

- Edsger Dijkstra

---

<div class="post-metadata">

**Author:** ![2tcreative](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/2/a3d4f5/32.png) [@2tcreative](https://www.ruby-forum.com/u/2tcreative)\
**Post date:** [September 25, 2007, 11:09pm UTC](https://www.ruby-forum.com/t/source-a-javascript-and-stylesheet-into-rhtml-file/114557/5 "2007-09-25T23:09:50Z")

</div>

Phlip wrote:

> Tim Trampedach wrote in message ne\
> 
> > I’m trying to do a quick dump of a javascript and style sheet located in  
> > their respective /public directories into an rhtml file.
> 
> \<%=h File.read(RAILS\_ROOT + ‘/public/javascript/my\_source.js’) %\>
> 
> This is half introductory Ruby and half introductory Rails, so one might  
> consider reading a little of the excellent books on these subjects,  
> offline, for a while!

Rails questions are better directed to Rails mailing list, where you’ll  
get better, faster, information.

–  
James B.

“Judge a man by his questions, rather than his answers.”

- Voltaire
