11

I am a .NET developer and I just had the chance to play with Ruby on Rails this weekend.

In .NET we separate layers of the application by creating separate class library projects. From the design pattern standpoint, do we have to do that in Rails too or is it just one whole project with everything in it?

  • 1
    +1, I can find loads of coding tutorials but there isn't anything on "how do I manage the layout of this semi complex project" that I can find for most languages. – Wyatt Barnett Mar 5 '13 at 21:12
  • I haven't read the Pragmatic Press' Ruby book, but if it's anything like Erlang, they do a good job at teaching you not just the syntax of the language but also the idioms. Perhaps someone else can comment on that. – Michael Brown Mar 5 '13 at 21:19
3

You'll find that Rails apps start as single repos. The more successful ones (Twitter, Square, many others) split into multiple codebases as they grow into that requirement. Those additional codebases can be daemons, services, gems, Rails Engines, or something else.

This refactoring into multiple projects isn't done until it proves necessary, because YAGNI. Bifurcating your project on day 1 slows prototyping time, and prototyping speed is a key strength of Ruby and of Rails. You'll want to keep in mind that creating or a class in Ruby costs almost nothing, as does breaking apart a well-desined class. Your pure Ruby code will live mostly under /app/ (app/models, app/views app/controllers, app/helpers) and /lib/. Your static assets, layered JS/Coffee includes, and CSS/Sass/etc includes are going to be in /app/assets.

Understanding why breaking apart a Ruby class is so easy requires a bit of reading on duck typing and the understanding that Ruby's interfaces aren't as ironclad as you might be used to in a less dynamic environment.

Here are a few links that might interest you:

Good luck with your projects!

0

In Ruby libraries are called gems, see http://www.ruby-lang.org/en/libraries/, and is used much the same way as .NET class libraries.

  • 1
    Yes. But my question is; in terms of good design pattern and good programming practice, do we separate models and business rules from the main rails project? Sorry if my question is confusing. I just got into rails and I don't really know how to explain it. It's just different.. – Ryan Adriano Mar 6 '13 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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