Forum: Ruby on Rails where should I put my hand-coded classes

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Pradeep S. (Guest)
on 2006-05-02 01:46
I have a class that is hand-coded (not generated using generator).

Is there a preferred location for the file.

app/components ?

does it matter?


Thanks,
Joe (Guest)
on 2006-05-02 05:35
/lib I'm pretty sure. That's where me puts 'em.

Joe
Steve R. (Guest)
on 2006-05-02 09:42
You should put them in RAILS_ROOT/lib if they are app specific. If you
plan to use them on multiple apps, consider writing a plugin.

Note: code in /lib is loaded only once so unless you use
require_dependency, you'll have to restart the server when you make
changes. Also, it's good practice to wrap your code in a module to
reduce the chance of a namespace collision.


Pradeep S. wrote:
> I have a class that is hand-coded (not generated using generator).
>
> Is there a preferred location for the file.
>
> app/components ?
>
> does it matter?
>
>
> Thanks,
Pradeep S. (Guest)
on 2006-05-02 10:09
Just a follow-up question.

I don't see RAILS_ROOT/lib dir. does it suppose to exist by default or
do I need to create it with the first class.

Making sure, that I am looking at the right place.

Thanks,



Steve R. wrote:
> You should put them in RAILS_ROOT/lib if they are app specific. If you
> plan to use them on multiple apps, consider writing a plugin.
>
> Note: code in /lib is loaded only once so unless you use
> require_dependency, you'll have to restart the server when you make
> changes. Also, it's good practice to wrap your code in a module to
> reduce the chance of a namespace collision.
>
>
> Pradeep S. wrote:
>> I have a class that is hand-coded (not generated using generator).
>>
>> Is there a preferred location for the file.
>>
>> app/components ?
>>
>> does it matter?
>>
>>
>> Thanks,
Marcel Molina Jr. (Guest)
on 2006-05-03 20:58
(Received via mailing list)
On Mon, May 01, 2006 at 11:46:43PM +0200, Pradeep S. wrote:
> I have a class that is hand-coded (not generated using generator).
>
> Is there a preferred location for the file.
>
> app/components ?
>
> does it matter?

Hey Pradeep,

Not components. Put it in lib/.

marcel
Larry W. (Guest)
on 2006-05-03 20:58
(Received via mailing list)
These things generally go in /lib.
Ray B. (Guest)
on 2006-05-03 20:59
(Received via mailing list)
Pradeep S. wrote:
> Just a follow-up question.
>
> I don't see RAILS_ROOT/lib dir. does it suppose to exist by default or
> do I need to create it with the first class.
>
> Making sure, that I am looking at the right place.

RAILS_ROOT is a constant that identifies the root directory of your
application. It is the directory that contains the app, config, log,
public, script and vendor directories.

It should also contain lib, assuming you created your application with
rail, so you should not have to create it.

--

Ray
Alain R. (Guest)
on 2006-05-03 21:00
(Received via mailing list)
Steve R. wrote:

    > Note: code in /lib is loaded only once so unless you use
    > require_dependency, you'll have to restart the server when you
make
    > changes.


To avoid having to restart the server, I just make them reloadable:

    # file: lib/foo.rb:
    class Foo
        include Reloadable
        ...
    end

Alain
This topic is locked and can not be replied to.