Ruby on Rails Introduction:-
Ruby on Rails is an open supply framework for building powerful web applications. It was created in 2004 with the aid of David Heine Meier Hansson and is based on the “Ruby” language. The unique factor to understand approximately Rails is that it may work with a couple of sorts of servers and databases.
It can expand a web application at least ten times quicker than you can assemble a standard Java framework. Rails are extremely productive web-utility framework.
Why is Ruby on Rails used?
With the help of Rails framework, developers can construct websites and programs because it abstracts and simplifies common repetitive duties. Rails are written in Ruby, the programming language which is likewise used alongside Rails. Ruby is to Rails as PHP is to Symfony and Zend, or as Python is to Django.
With this framework, persons who know Ruby can fastly create web programs. The programming language Ruby itself has already existed due to the fact 1995, however, Ruby on Rails is the “killer app” that made it famous. Ruby is pretty much like Python, a programming language that is used lots for Ubuntu computing device applications.
A framework is a software, set of applications, or code library that writes a maximum of your application for you. When you operate a framework, your activity is to jot down the parts of the software that makes it to the specific stuff you want.
There are three primary tasks to perform when writing a Rails application, they are –
- Describe and model your application’s domain −
The universe of the application is a domain. The domain can be a tune keep, a university, a dating provider, a deal with book, or a hardware stock. So right here you have to parent out what’s in it, what entities exist in this universe and how the gadgets in it relate to each different. This is equivalent to modeling a database shape to maintain the entities and their relationship.
- Specify what can happen in this domain −
The model of the domain is static; users have to make it dynamic. Addresses can be added to an address book. Musical rankings can be bought from song stores. Users can log in to a relationship provider. Students can check in for instructions at a university. You need to discover all the feasible scenarios or moves that the elements of your domain can take part in.
- Choose and design the publicly available views of the domain −
At this point, you could start wondering in Web-browser phrases. Once you’ve decided that your domain has students and that they could check in for classes, you may envision a welcome page, a registration page, and a confirmation web page, etc. Each of these pages, or perspectives, suggests the consumer how matters stand at a sure factor.
Ruby on Rails MVC Framework:-
The Model View Controller precept divides the work of a utility into three separate but intently cooperative subsystems.
It continues the relationship between the objects and the database and handles validation, affiliation, transactions, and extra.
This subsystem is applied in Active Record library, which affords an interface and binding between the tables in a relational database and the Ruby program code that manipulates database statistics. Ruby approach names are automatically generated from the sector names of database tables.
It is a presentation of statistics in a particular layout, triggered by way of a controller’s selection to offer the records. They are script-primarily based template structures like JSP, ASP, PHP, and very easy to combine with AJAX generation.
This subsystem is carried out in ActionView library that is an Embedded Ruby (ERb) based totally device for defining presentation templates for records presentation. Every Web connection to Rail’s software outcomes inside the showing of a view.
The facility within the utility that directs site visitors, on the one hand, querying the models for unique data, and then again, organizing that facts (looking, sorting, messaging it) into a sort that fits the requirement of a given view.
This subsystem is implemented in ActionController, that’s a records dealer sitting among ActiveRecord (the database interface) and ActionView (the presentation engine).
Pictorial Representation of MVC Framework:-
Following is the pictorial representation of Ruby on Rails Framework −
Ruby on Rails Directory Structure:-
Here find the purpose of each directory:-
- app− It organizes the application additives. The subdirectories of the app directory hold the view (views), the controller (controllers), and the backend business logic (model).
- App/controllers− The controllers are one of the subdirectory wherein Rails seems to locate the controller lessons. A controller handles a web request from the user.
- app/helpers− The next subdirectory named helpers’ holds any helper lessons that are used to assist the model, view, and controller lessons. This facilitates to preserve the model, view, and controller code small, focused, and uncluttered.
- app/models− The models’ subdirectory holds the classes that model and wrap the information stored in our application’s database. In most frameworks, this a part of the utility can develop quite messy, tedious, verbose, and error-inclined. Rails make it useless simple!
- app/view – This the type of directory which holds the display templates to fill in with statistics from our application, convert to HTML, and go back to the consumer’s browser.
- App/view/layouts− Hold the template documents for layouts to be used with views. This model the not unusual header/footer method of wrapping perspectives.
- Components− this directory holds components, tiny self-contained programs that bundle model, view, and controller.
- Config− This is the type of directory that consists of the small amount of configuration code that your application will want, such as database configuration (in database.Yml), Rails surroundings shape (environment.rb), and routing of incoming web requests (routes.Rb).
- Db– Db is one type of directory where Rails application will have model objects that access relational database tables. A relational database can be managed with the created scripts and then place in this directory.
- Doc− RubyDoc is one form of a framework of Ruby that may robotically generate documentation for the created code. This type of listing holds all the RubyDoc-generated Rails and software documentation.
- Lib– Lib is the type of directory where libraries are stored unless they explicitly belong elsewhere (such as vendor libraries).
- Log− Error logs go here. Rails create scripts that assist you to control numerous blunders logs. You’ll locate separate logs for the server (server.Log) and each Rail’s surroundings (development.Log, test.Log, and production.Log).
- Script– This is the form of listing that holds scripts to release and manipulate the numerous tools that you will use with Rails. For instance, there are scripts to generate code (generate) and release the web server (server).
- test− This is the type of directory where the tests were written and also the created rails go here. You’ll see a subdirectory for mocks (mocks), unit exams (unit), fixtures, and practical exams (useful).
- tmp − This type of directory is used by rails to hold temporary files for intermediate processing.
- vendor− Libraries furnished by vendors who come under third party (which includes protection libraries or database utilities beyond the primary Rails distribution) pass right here.