# Where to put custmized files in Rails app?

**URL:** <https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071>\
**Category:** Rails\
**Created:** [November 11, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071 "2008-11-11T21:25:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 11, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/1 "2008-11-11T21:25:02Z")

</div>

All,

This is the first time to play on Rails application. Simple questions:  
where to locate/store my own \*.rb, and \*.txt files in my Rails app?  
I put my \*.rb in the components folder so that controllers can see  
them without problems. Is this the right place to do that?  
But I may not know where to put \*.txt files and how to locate them in  
controllers.

## Thank you in advance.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 11, 2008, 10:15pm UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/2 "2008-11-11T22:15:46Z")

</div>

the “components” dir is deprecated and removed in v2.0+ AFAIK

you’d be better off using the lib dir or making a plugin.

On Nov 11, 1:35 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 12, 2008, 5:53am UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/3 "2008-11-12T05:53:52Z")

</div>

Thank you for the response.

I am practicing on v1.7 and it works fine. But, if I move the code  
from components to comp dir in lib, the controller can not fine those  
fine any more. If I put those files in lib directly, it woks fine  
again. How can I maintain a structure of directories in Rails?

Thanks,

-

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 12, 2008, 10:20am UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/4 "2008-11-12T10:20:52Z")

</div>

Why do you need to maintain a directory of files? There are preset  
directories already for anything you do with the Rails MVC framework  
and the lib directory gives you a spot to put additional modules.  
Static files that get pushed to the users belong in the public/  
directory, etc.

You will need to require the files manually if you use your own  
subdirectories.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 12, 2008, 2:14pm UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/5 "2008-11-12T14:14:19Z")

</div>

The lib directory is included by rails automatically, so any file in  
there will be included. If you put it elsewhere you’ll have to  
specifically require them yourself.

On Nov 11, 11:52 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 12, 2008, 7:42pm UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/6 "2008-11-12T19:42:15Z")

</div>

I may not want to have a directory of files anywhere that much but,  
what if I want to separate my \*rb files from \*xml files? The case I am  
having now is that I have to put all my own files in a signal lib  
directory which I may not like it very much. Is this ture that I  
cannot have a sub directory in lib?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 12, 2008, 9:52pm UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/7 "2008-11-12T21:52:46Z")

</div>

Thank you, jemminger.

That works for me now. However, I’ve got another issue. I have an  
my\_parse.rb file to parse an xml file. The directory for these files  
is lib/myfiles/my\_parse.rb, and lib/myfiles/xml/aa.xml. And also I  
have a test file in test/unit/my\_parse\_test.rb. The error message is:  
Errno::ENOENT: No such file or directory - xml/aa.xml when I put the  
path to the aa.xml flie like this - xml/aa.xml in my\_parse\_test.rb.  
But, it is OK if the aa.xml is in the same dir as my\_parse.rb is with  
the path - aa.xml.  
So, what is the right path to the aa.xml in my\_parse.rb if I put  
aa.xml file in xml/aa.xml?  
(like this: lib/myfiles/my\_parse.rb, and lib/myfiles/xml/aa.xml)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 12, 2008, 8:56pm UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/8 "2008-11-12T20:56:16Z")

</div>

you can have as many subdirectories in lib or anywhere else you want.  
you will just have to explicitly require those files or write  
something to auto-require the files in those dirs.

e.g. if you make “lib/myfiles/foo.rb”, you’ll have to put “require  
‘myfiles/foo.rb’” to use it

On Nov 12, 1:41 pm, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 13, 2008, 3:35am UTC](https://www.ruby-forum.com/t/where-to-put-custmized-files-in-rails-app/153071/9 "2008-11-13T03:35:53Z")

</div>

All right, I got it. I should use **FILE** to identify the path of  
my\_parser.rb and then to locate the xml file.
