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.
612a5333e356c4f765230d9ac06e5c8c?d=identicon&s=25 Pradeep Sethi (psethi2000)
on 2006-05-01 23: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,
429500a5a54600958c9c7ac032a37f66?d=identicon&s=25 Joe (Guest)
on 2006-05-02 03:35
/lib I'm pretty sure. That's where me puts 'em.

Joe
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-05-02 07: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 Sethi 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,
612a5333e356c4f765230d9ac06e5c8c?d=identicon&s=25 Pradeep Sethi (psethi2000)
on 2006-05-02 08: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 Ross 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 Sethi 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,
Cee0292fffa691f1fb320d5400200e99?d=identicon&s=25 Marcel Molina Jr. (Guest)
on 2006-05-03 18:58
(Received via mailing list)
On Mon, May 01, 2006 at 11:46:43PM +0200, Pradeep Sethi 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
D4b246038154d7cc2363256bd25a4fe0?d=identicon&s=25 Larry White (Guest)
on 2006-05-03 18:58
(Received via mailing list)
These things generally go in /lib.
E28c35323f624b8b9ed8712e25105454?d=identicon&s=25 Ray Baxter (Guest)
on 2006-05-03 18:59
(Received via mailing list)
Pradeep Sethi 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
0091f92762685860109bbcb02edfdf27?d=identicon&s=25 Alain Ravet (Guest)
on 2006-05-03 19:00
(Received via mailing list)
Steve Ross 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.