Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a rails app. I'm writing code to integrate it with a third-party service, "Foo Bar". The integration affects many parts of the system -- models, controllers, and an API wrapper.

Thus far I've been putting the integration stuff into the modules of each model and controller. So inside app/models/user/foo_bar.rb is User::FooBar, which I then include into my user model.

I have the API wrapper inside lib/foo_bar_api.rb.

It occurred to me today that perhaps I should have all my integration code in lib. So lib/foo_bar/user.rb would contain FooBar::User, which I then include in my user model.

Is there a particularly standard way of doing this, or is it 6 of one, half-dozen of another?

(p.s., this is my first question -- it's appropriate for here, right?)

share|improve this question
You will find that Rails makes it difficult to namespace your models by putting them inside modules (or classes). – Rein Henrichs Oct 31 '11 at 9:00

I think it's a matter of preference.

I would suggest going with a FooBar::User (foo_bar/user.rb) approach. It will keep your FooBar related code closer together, and naming of the files will be more to the point. Everything user rlated will be user.rb in sperate folders. While if you'd do it the other way you'd have a lot of foo_bar.rb files.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.