Where to put custmized files in Rails app?

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.

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

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

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,

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.

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.

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?

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

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)

All right, I got it. I should use __FILE__ to identify the path of my_parser.rb and then to locate the xml file.