# Importing file in html (noob)

**URL:** <https://www.ruby-forum.com/t/importing-file-in-html-noob/126095>\
**Category:** Rails\
**Created:** [January 15, 2008, 12:18pm UTC](https://www.ruby-forum.com/t/importing-file-in-html-noob/126095 "2008-01-15T12:18:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![statictony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@statictony](https://www.ruby-forum.com/u/statictony)\
**Post date:** [January 15, 2008, 12:18pm UTC](https://www.ruby-forum.com/t/importing-file-in-html-noob/126095/1 "2008-01-15T12:18:43Z")

</div>

Hi People,

I’m pretty new to rails so please bear with me on this.

I’m wanting to pull a text file into my rhtml page to use as the header  
part of my site. I know I can use layouts but it isn’t pratical for my  
problem as there could be hundreds of user made headers.

So there are two ways I can see this happening. One is to store the  
location of the file in the database and use that with some sort of ruby  
html include tag in the html.

The second is to some how pull the header text from the file into the  
model and then output it to the page.

So my question is which of these is the “rails” 😉 way to do this and  
how would each of these ideas work in code as I dont have a clue.

hope I’ve made sense

cheers  
Tony

---

<div class="post-metadata">

**Author:** ![statictony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@statictony](https://www.ruby-forum.com/u/statictony)\
**Post date:** [January 15, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/importing-file-in-html-noob/126095/2 "2008-01-15T18:05:52Z")

</div>

On 1/15/08, Mathew M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m wanting to pull a text file into my rhtml page to use as the header  
> part of my site. I know I can use layouts but it isn’t pratical for my  
> problem as there could be hundreds of user made headers.

Do you know about render?

\<%= render :partial =\> ‘some\_dir/some\_header’ %\>

[http://api.rubyonrails.com/classes/ActionController/Base.html#M000452](http://api.rubyonrails.com/classes/ActionController/Base.html#M000452)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![statictony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@statictony](https://www.ruby-forum.com/u/statictony)\
**Post date:** [January 15, 2008, 6:37pm UTC](https://www.ruby-forum.com/t/importing-file-in-html-noob/126095/3 "2008-01-15T18:37:49Z")

</div>

Ahh I didn’t you could use a partial like that doh!

So is that the best way…there is no way to pull the directory contents  
into a property in the model?

---

<div class="post-metadata">

**Author:** ![statictony](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9f8e36/32.png) [@statictony](https://www.ruby-forum.com/u/statictony)\
**Post date:** [January 15, 2008, 9:50pm UTC](https://www.ruby-forum.com/t/importing-file-in-html-noob/126095/4 "2008-01-15T21:50:30Z")

</div>

On 1/15/08, Mathew M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Ahh I didn’t you could use a partial like that doh!
> 
> So is that the best way…

Compared to what other way?

> there is no way to pull the directory contents  
> into a property in the model?

Sure. I would use Dir.glob.

[http://www.ruby-doc.org/core/classes/Dir.html#M002347](http://www.ruby-doc.org/core/classes/Dir.html#M002347)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)
