Reputation: 13308
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.
Upvotes: 6
Views: 3879
Reputation: 15560
After 4+ years, this is still a relevant question. It appears there's a confusion around what people mean by application tiers.
Previous answers are of course correct when you think of MVC tiers, and when you define an application as being 3-tier if it has proper models, views and controllers. Of course Rails is by default 3-tier in this sense, with notable differences to ASP.NET MVC as pointed out by others.
However, I have a feeling that the original question referred to how things are deployed (I may of course be wrong, but people looking at this question may still be looking for this). Enterprise applications often have the requirement to be three tier in a sense that a web application (presentation) can only talk to services (business logic), which can only talk to a database due to network level restrictions, and for security reasons.
In this model, the front-end web application performs security functions (protection against several types of attacks like CSRF or Clickjacking, maybe session management, etc.), and presents any data read from services on application servers. These application servers are not directly accessible by endusers, often trust web servers (or not, depending on the security model), and persist their data in databases, which cannot be accessed directly by web servers. In a Windows environment, web, app and database servers are typically in different domains.
Rails, as described in pretty much all tutorials, is a web and app server at the same time, which does not fit the latter model, and there really are not much resources available on how to do this properly. However, especially with Rails 5, it is very easy to turn Rails into a proper service to be used as an application server with an API (see the API-only Applications Guide), and it is also possible to create another Rails application for the web (presentation) tier. You will have to solve quite a lot of things for yourself though, from authentication between web and app to making service queries from web to app, especially now that ActiveResource is kind of retired.
Upvotes: 4
Reputation: 1715
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.
Upvotes: 5
Reputation: 1534
Ruby on Rails is a three tier (MVC) architecure. In rails the data layer is the called the Model, the buisness layer is called the Controller, and the user interface layer is called Views.
Here are a couple good places to start: rails guides, rails tutorial for rails 3.2
Upvotes: 4