Ok... I guess now you are ok with Ruby(I will give more details on Ruby, but I want to go parallel with Rails so that you people can have good experience) and want to go ahead with Rails... Why Rails??? Because Ruby On Rails(RoR) is more famous because of web application and for that you need to know the heart of it YES it is RAILS. Rails is actually a framework, which is written in Ruby language created by David Heinemeier Hansson- from his work on Basecamp(a project management tool)
Few things which Rails follows -
1. DRY - Don’t Repeat Yourself - code should not be repeated - which inspires us for modular-ism.
2. Convention over configuration - Rails makes the assumption about your requirement and process rather than specifying each thing.
3. REST is the best architecture for web application.
Now if you want to know Rails more you have to know three things
A. about MVC structure.
B. Components of Rails
C. REST
A. What is MVC?
Rails follow this Model, View, Controller architecture, usually just called MVC. Through this model
1. we can isolate business logic from the user interface,
2. helps to keep code dry &
3. helps for maintenance for different types of code.
A model generally handles all the database related and business logic related issues/code. Normally Most of the code is being written here for applications. It is the HEART of MVC architecture. Model takes request from controller & after executing that request sends back the control to controller. It represent the information/data of the application and the rules to manipulate that data. Its main task is to manage the rules of interaction with a corresponding database table. Each table in your database will correspond to one model in your application(though we can customize it). The bulk of your application’s business logic will be concentrated in the models. In the case of Rails, tables names comes with plural form of model name.
Views are the user interface of the application. In Rails, views are often HTML files with embedded Ruby code that perform tasks related solely to the presentation of the data. Views handle the job of providing data to the web browser or other tool that is used to make requests from your application. It takes requests from user and request controller to perform the task and again render back the result to user.
Controllers are the middle man or the communicator between models and views. In Rails, controllers are responsible for processing the incoming requests from views i.e the web browser, interrogating the models for data, and passing that data on to the views for presentation.
The islands of Rails are
- 1. Action Pack(Action Controller + Action Dispatch + Action View)
- 2. Action Mailer
- 3. Active Model
- 4. Active Record
- 5. Active Resource
- 6. Active Support
- 7. Railties
- Using resource identifiers such as URLs to represent resources.
- Transferring representations of the state of that resource between system components.
Here is a brief about Rails components:-
A single gem "Action Pack" contains Action Controller, Action View and Action Dispatch. The 'View-Controller' part of 'Model-View-Controller'.
In Rails application(app.) Action Controller manages the controllers. It is a framework which processes incoming requests to app., extracts parameters, and dispatches them to the intended action. Its main task is to session management, template rendering, and redirect management.
Action View manages the user interface/views of the app. It can create both HTML and XML output by default. Its main task is rendering templates, including nested and partial templates, and also built-in AJAX support.
Action Dispatch manages routing of web requests and dispatches them as your requirement, it can be done for both/either to your application or any other Rack application.
Action Mailer framework provides us e-mail services. To receive and process incoming email and send simple plain text or complex multipart emails based on flexible templates - we use it.
Active Model is the key to define interface between the Action Pack gem services and Object Relationship Mapping(ORM) gems like Active Record. You also can utilize other ORMframeworks in place of Active Record if your application needs this via active model.
Active Record is the heart for the models in a Rails application. It gives us database independence, basic CRUD functionality, advanced finding capabilities, and the ability to relate models to one another, among other services.
Active Resource framework to managing the connection between business objects and RESTful web services. It implements a way to map web-based resources to local objects with CRUDsemantics.
Active Support is an huge collection of utility classes and standard Ruby library extensions that are used in Rails, both by the core code and by your applications.
Railties is the core Rails code that builds new Rails applications and communicate among the various frameworks and plugins together in any Rails application.
REST stands for Representational State Transfer and is the foundation of the RESTful architecture. We got it from Roy Fielding’s doctoral thesis, which comes to two main principles:
For example, the following HTTP request:
UPDATE/books/58
would be understood to refer to a book resource with the ID of 58, and to indicate a desired action – updating that resource. REST is a natural style for the architecture of web applications, and Rails provides this shielding to you from many of the RESTful complexities and browser quirks.
Thanks to(official sites of...) => Ruby guide & Rails Casts & Ruby About & Wikipedia And RubyOnRails
Thanks to(official sites of...) => Ruby guide & Rails Casts & Ruby About & Wikipedia And RubyOnRails