Ruby on Rails is an open source framework for Web development in Ruby, an object-oriented programming (OOP) language similar to Perl and Python.
The principle difference between Ruby on Rails and other frameworks for development lies in the speed and ease of use that developers working within the environment enjoy. Changes made to applications are immediately applied, avoiding the time consuming steps normally associated with the web development cycle. According to David Geary, a Java expert, the Ruby-based framework is five to 10 times faster than comparable Java-based frameworks. In a blog posting, Geary predicted that Rails would be widely adopted in the near future.
Rails is made up of several components, beyond Ruby itself, including:
Active record, an object-relational mapping layer
Action pack, a manager of controller and view functions
Action mailer, a handler of email
Action web services
Prototype, an implementer of drag and drop and Ajax functionality
Rails can run on most Web servers that support CGI. The framework also supports MySQL, PostgreSQL, SQLite, SQL Server, DB2 and Oracle. Rails is also an MVC (model, view, controller) framework where all layers are provided by Rails, as opposed to reliance on other, additional frameworks to achieve full MVC support. Invented by David Heinemeier Hanss, Ruby On Rails has been developed as an open-source project, with distributions available through rubyonrails.org.
Example
Here is a sample Ruby code to print "Hello Ruby"
# The Hello Class
class Hello
def initialize( name )@name = name.capitalize
enddef salute
puts "Hello #{@name}!"endend
# Create a new object
h = Hello.new("Ruby")
# Output "Hello Ruby!"
h.salute
Output − This will produce the following result −
Hello Ruby!
Installation
To develop a web application using Ruby on Rails Framework, you need to install the following software −
Ruby
The Rails Framework
A Web Server
A Database System
We assume that you already have installed a Web Server and a Database System on your computer. You can use the WEBrick Web Server, which comes with Ruby. Most websites however use Apache or lightTPD web servers in production.
Install Ruby on Rails below :
Installation Verification
You can verify if everything is set up according to your requirements or not. Use the following command to create a demo project.
tp> rails new demo
Output
It will generate a demo rail project; we will discuss about it later. Currently we have to check if the environment is set up or not. Next, use the following command to run WEBrick web server on your machine.
tp> cd demo
tp> rails server
It will generate auto-code to start the server
Now open your browser and type the following −
http://localhost:3000
It should display a message, something like, "Welcome aboard" or "Congratulations".
Advantages and Disadvantages of Ruby on Rails
When it comes to web application development, there is a great variety of tools to choose from. You should consider such factors as a learning curve, scalability, hosting requirements, ease of installation, documentation to make the right decision.
Advantages:
1. Ruby on Rails guarantees the resistance of your web page or app to common vulnerabilities. With this framework, your web product will be protected from the following threats:
Cross-Site Scripting
SQL Injection
Cross-Site Request Forgery
Insecure Direct Object Reference or Forceful Browsing.
2. RoR is famous for intuitive, compact, and easy-to-understand syntax which means the highest usability to programmers.
3. The framework offers a great number of free open-source libraries called gems. They extend or modify the existing functionality of web apps and provide developers with solutions to common issues.
4. Its active members create Ruby on Rails dedicated websites, forums and chat rooms that help developers find professional answers from other coders who have experienced a similar problem and came up with a solution.
5. Implementation of complex business logic in a web application is easy with Ruby on Rails.
6. React, Vue, and Angular tools are widely used together with Ruby on Rails due to the easy integration of RoR.
Disadvabtages
1. Runtime speed and performance
2. Lack of flexibility
3. Lower popularity
Source: Tutorialpoint
Commentaires