Where do I put my own class?

Correct, lib is the place.

Ryan Bigg wrote:

Correct, lib is the place.

Thanks. And how do I access it in my controller?

Just like any normal class (usually)... you may have to require the file in config/environment.rb, but I think files in lib are automatically loaded.

Ryan Bigg wrote:

Just like any normal class (usually)... you may have to require the
file in config/environment.rb, but I think files in lib are
automatically loaded.

Perfect. :slight_smile:

Depending on what type of class you're thinking of: you can also
create a class in the app/models folder, even if your model won't be
an ActiveRecord model (so no associated database table). Think of
using that if your class is really a model, so creating objects that
you want to view and manipulate in the usual MVC way. For example a
class of static objects that can be auto-generated at runtime (and
don't need a database table because they will never change) like the
12 months of a year could be encapsulated in a model.

Dirk.

deegee wrote:

Depending on what type of class you're thinking of: you can also
create a class in the app/models folder, even if your model won't be
an ActiveRecord model (so no associated database table). Think of
using that if your class is really a model, so creating objects that
you want to view and manipulate in the usual MVC way. For example a
class of static objects that can be auto-generated at runtime (and
don't need a database table because they will never change) like the
12 months of a year could be encapsulated in a model.

Dirk.

On 20 aug, 08:09, P�l Bergstr�m <rails-mailing-l...@andreas-s.net>

I see. That makes sense. Just a thought, but perhaps that would be the
place to put different language variables? If a user set his/here
language settings to 'swe' all variables that is in there and in the app
would output the right word in Swedish instead of English – that I've
statically entered in a class.

yeah you r right .

you may have to require the file in config/environment.rb,

Nope, no need

but I think files in lib are automatically loaded.

Yes they are.

Hi,
Different language variables bundled in a class I would definetely put
in the lib folder like Ryan suggested; also if you want to override or
extend some standard Rails classes, that's where you should do it. The
other options you have apply to more specific cases:
- My suggestion to put some of your own classes in the app/models
folder should only be done if your class is really a model (just not
necessarily an ActiveRecord model). So a Class with objects that can
be viewed and possibly manipulated by the user.
- If you create a Module/Class with very generic behaviour that you
want to reuse also in your other applications, make your own plugin
(in vendor/plugins).

Cheers,
Dirk.