views:

35

answers:

1

I'm new to Rails, and have been learning with Rails 3 on a side project. There are times when I want to write some code that does not belong in my models or in my controllers - concerns that are related to a model and/or controller, but i don't want to clutter up either of them with the implementation details of what i am writing.

For example: a project i'm building uses Janrain's authorization system (RPX) so i can get oauth, openid, google, etc. authorization. there's a nice chunk of API code that they provide so i don't have to write it all myself. this code doesn't belong in the login controller or in the user module. it's authorization code, so it needs to be accessible by the login controller, but it's not part of that controller.

Where do you put this code? it's not model code. it doesn't belong in the controller.

... thanks in advance.

+3  A: 

You should be able to use lib folder in your root directory (unless it's changed in Rails 3).
You can refer classes from there without require statement.

Nikita Rybak
Beat me by 30 seconds :) +1
Matchu
Rails 3 doesn't auto-require from lib, so you should explicitly require it.
Andrew Vit
Andrew - do i need to use anything like Rails.root to get to the lib folder? or do i just use 'lib/' ?
Derick Bailey