Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three-tier architecture in Ruby and Ruby on Rails

I'm an ASP.NET MVC developer who decided to learn Ruby and Ruby on Rails. I already know something and created a web site on RoR. Developing on ASP.NET MVC, I have always used a three-tier architecture: data layer, business layer and UI (or presentation) layer.

Trying to use this approach in a Ruby on Rails application, I found that there was no information about it (or maybe I just couldn't find it?).

Perhaps someone can suggest me how to create or use three-tier architecture on Ruby on Rails?

P.S. I use ruby 1.9.3 and Ruby on Rails 3.2.3.

like image 538
Alexandre Avatar asked May 28 '12 11:05

Alexandre


1 Answers

I would suggest following Ruby on Rails (RoR) style while making RoR applications. Rails way of seeing MVC architecture does not quite fit into Asp.net 3 Tier architecture.

UI (Presentation Layer | View)

These two follow the same logic. No major differences.

Controller (Business Layer | Controller)

Both Business Layer and Controller receive requests from UI and they send back responses. In Asp.net Business Layer takes care of validation and business logic. But in Rails, validations and business logic belong to Model.

Model (Data Layer | Model)

Rails' Model does more than Asp.net's Data Layer. Model deals with business logic and validations. Data Layer and Model take care of data transfer to storage.

When moving from Asp.net to RoR, try to keep your controllers thin. RoR sets serious constraints on how you structure your web application. And once you'll stick with those, you'll make more professional RoR apps.

like image 102
hade Avatar answered Sep 28 '22 19:09

hade