1-click AWS Deployment 1-click Azure Deployment
Overview
What is Ruby?
Ruby is the constructive combination of −
- Smalltalk’s conceptual grace,
- Python’s affluence of use and learning, and
- Perl’s practicality.
Ruby is −
A high-level programming language.
Interpreted like Perl, Python, Tcl/TK.
Object-oriented like Smalltalk, Eiffel, Ada, Java.
Why Ruby?
Ruby was basically originated in Japan and now it is popular in US and Europe as well. The following factors contribute towards its popularity −
- Easy to learn
- Open source (very liberal license)
- Rich libraries
- Very easy to extend
- Truly object-oriented
- Less coding with fewer bugs
- Helpful community
Although we have many reasons to use Ruby, there are a few drawbacks as well that you may have to consider before implementing Ruby −
- Performance Issues− Although it rivals Perl and Python, it is still an interpreted language and we cannot compare it with high-level programming languages like C or C++.
- Threading model− Ruby does not use native threads. Ruby threads are simulated in the VM rather than running as native OS threads.
What is Rails?
- An extremely productive web-application framework.
- Written in Ruby by David Heinemeier Hansson.
- You could develop a web application at least ten times faster with Rails than you could with a typical Java framework.
- An open source Ruby framework for developing database-backed web applications.
- Configure your code with Database Schema.
- No compilation phase required.
Full Stack Framework
- Includes everything needed to create a database-driven web application, using the Model-View-Controller pattern.
- Being a full-stack framework means all the layers are built to work seamlessly together with less code.
- Requires fewer lines of code than other frameworks.
Convention over Configuration
- Rails shuns configuration files in favor of conventions, reflection, and dynamic runtime extensions.
- Your application code and your running database already contain everything that Rails needs to know!
Rails Strengths
Rails is packed with features that make you more productive, with many of the following features building on one other.
Metaprogramming
Where other frameworks use extensive code generation from scratch, Rail framework uses Metaprogramming techniques to write programs. Ruby is one of the best languages for Metaprogramming, and Rails uses this capability well. Rails also uses code generation but relies much more on Metaprogramming for the heavy lifting.
Active Record
Rails introduces the Active Record framework, which saves objects into the database. The Rails version of the Active Record discovers the columns in a database schema and automatically attaches them to your domain objects using metaprogramming.
Convention over configuration
Most web development frameworks for .NET or Java force you to write pages of configuration code. If you follow the suggested naming conventions, Rails doesn’t need much configuration.
Scaffolding
You often create temporary code in the early stages of development to help get an application up quickly and see how major components work together. Rails automatically creates much of the scaffolding you’ll need.
Built-in testing
Rails creates simple automated tests you can then extend. Rails also provides supporting code called harnesses and fixtures that make test cases easier to write and run. Ruby can then execute all your automated tests with the rake utility.
Three environments
Rails gives you three default environments: development, testing, and production. Each behaves slightly differently, making your entire software development cycle easier. For example, Rails creates a fresh copy of the Test database for each test run.
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.
Rails works with many database systems, including MySQL, PostgreSQL, SQLite, Oracle, DB2 and SQL Server. Please refer to a corresponding Database System Setup manual to set up your database.
RUBY ON RAILS
Rails is a development tool which gives web developers a framework, providing structure for all the code they write. The Rails framework helps developers to build websites and applications, because it summaries and simplifies common repetitive tasks.Rails is written in Ruby, the programming language which is also used alongside Rails. Ruby is to Rails as PHP is to Symfony and Zend, or as Python is to Django. The appeal of Ruby to developers lies in the elegance and terseness of the language.
One of key principles of Ruby on Rails development (henceforth ‘Rails’) is convention over configuration. This means that the programmer does not have to spend a lot of time configuring files in order to get setup, Rails comes with a set of conventions which help speed up development.
Another characteristic of Rails is the emphasis on RESTful application design. REST (Representational State Transfer) is a style of software architecture based around the client-server relationship. It encourages a logical structure within applications, which means they can easily be exposed as an API (Application Programming Interface).
From project management point of view, the Ruby on Rails community advocate Agile web development – an iterative development method, that encourages collaborative and flexible approach, which is particularly well-suited for web application development with fast-changing requirements.
Since previous few years Ruby on Rails has increased a large and passionate following, but let’s consider the main opinions for and against Rails.
PROS AND CONS OF RAILS
WHY WE PREFER TO USE RUBY ON RAILS:
- The process of programming is much faster than with other frameworks and languages, partly because of the object-oriented nature of Ruby and the vast collection of open source code available within the Rails community.
- The Rails conventions also make it easy for developers to move between different Rails projects, as each project will tend to follow the same structure and coding practices.
- Rails is good for rapid application development (RAD), as the framework makes it easy to accommodate changes.
- Ruby code is very readable and mostly self-documenting. This increases productivity, as there is less need to write out separate documentation, making it easier for other developers to pick up existing projects.
- Rails has developed a strong focus on testing, and has good testing frameworks.
- Rails and most of its libraries are open source, so unlike other commercial development frameworks there are no licensing costs involved.
POTENTIAL RAILS PROBLEMS AND LIMITATIONS AND HOW TO OVERCOME THEM:
- Not all website hosts can support Rails
While it is true that not all web hosts support Rails, this is primarily because it can be more resource intensive than PHP, a fact which deters low-end shared-hosting providers. However, this is by no means a deal-breaker, and of course Rails-friendly hosts do exist, for example, Heroku and EngineYard.
Alternatively, you can host your Rails application on a Virtual Private Server (VPS) with Amazon EC2, Rackspace, or Linode. You will then have full control over the server and can allocate sufficient resources for your application.
- Java and PHP are more widely used, and there are more developers in these languages
The number of Ruby developers is growing year on year as more people switch to it from other programming languages. One of the main differences between the Ruby and other communities is the amount of open source code (gems) which is publicly available, as of writing there are 63,711 gems which you can use to enhance your application.
- Performance and Scalability
There have been apprehensions that Rails applications are not as fast as Java or C, which is true, but for the majority of applications it is fast enough. There are plenty of high-profile organizations which rely on Rails to power their sites including AirBnB, Yellow Pages, Groupon, Channel 5, and Gov.uk. There is also the option of running your application under JRuby, and we have the similar performance characteristics as Java.
—
Ruby on Rails is an extremely productive web application framework written in Ruby by David Heinemeier Hansson. This tutorial gives you a complete understanding on Ruby on Rails.Ruby originated in Japan and now it is gaining popularity in US and Europe as well. The following factors contribute towards its popularity.
A framework is a program, set of programs, and/or code library that writes most of your application for you. When you use a framework, your job is to write the parts of the application that make it do the specific things you want.
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.
Rails works with many database systems, including MySQL, PostgreSQL, SQLite, Oracle, DB2 and SQL Server. Please refer to a corresponding Database System Setup manual to set up your database.
Ruby on Rails is the successful combination of −
- Smalltalk’s conceptual elegance,
- Python’s ease of use and learning, and
- Perl’s pragmatism.
- A high-level programming language.
- Interpreted like Perl, Python, Tcl/TK.
- Object-oriented like Smalltalk, Eiffel, Ada, Java.
- Easy to learn
- Open source (very liberal license)
- Rich libraries
- Very easy to extend
- Truly object-oriented
- Less coding with fewer bugs
- Helpful community
Ruby provides a program called ERB (Embedded Ruby), written by Seki Masatoshi. ERB allows you to put Ruby codes inside an HTML file. ERB reads along, word for word, and then at a certain point, when it encounters a Ruby code embedded in the document, it starts executing the Ruby code.
You need to know only two things to prepare an ERB document −
- If you want some Ruby code executed, enclose it between <% and %>.
- If you want the result of the code execution to be printed out, as a part of the output, enclose the code between <%= and %>.
Features
4 Amazing Features of Rails 6.0
The most awaited features of the new version of Rails 6.0 are as follows:
Parallel Testing
Test’s performance is finally going to be improved (a lot!). Now you can use cores to your advantage of running big tests much faster. Each testing worker runs in its own thread – it should be reflected in the CPU monitor. The way of implementing tests is very important. We try to implement as many suitable tests as we can. It’s great news for us as more tests will no longer have that much of an impact on the execution time.
Native Webpacker Support
Webpacker was introduced a while back with the 5.1 version of Ruby on Rails. It makes using JavaScript pre-processor easier.We usually use it for JavaScript code, it works really well but it can also be used for CSS, images, fonts and assets as well. From now on, Sprockets is being replaced and Webpacker is the default JavaScript bundler for Rails through the new app/javascript directory.Presently, in modern applications, using traditional rails views is not so often anymore. User Interfaces are very interactive, there is a lot of dynamic elements which have to respond really fast.
Multiple database support
Another great feature of upcoming Rails 6.0 is the support for multiple simultaneous database connections. It’s a new, simple API for making that happen without the need to reach deeply into Active Record.Official RoR blog suggests using two databases to for example split the workflow between two replica databases for a performance boost or records segmentation into databases for scaling. We can definitely see multiple database support as an improvement in building microservices architecture.One of the real life examples where this feature could be really useful is our in-house project – Artinfo. In this project, there are two database connections, one for old users and one for those who just signed up. Now with Rails 6, this implementation would be much easier.
Zeitwerk
With this version of Rails a new code loader was introduced – Zeitwerk. It promises to load your project’s classes and modules on demand, no need to write require calls. Zeitwerk uses absolute file names making the loader more efficient. Your classes and modules are available everywhere. The team behind the loader claims that it is thread-safe and matches Ruby’s semantics for constants.
The following features are the reasons for using ruby 2 or higher:
Symbol Garbage Collector
In Ruby On Rails applications, we usually pass symbols all over the place, doing this opens the possibility of DoS attacks when our memory is consumed by symbols that never get garbage collected. Ruby 2.2.0 introduced changes in its garbage collector to be able to collect symbols.
Module #prepend
Allows to do insert a module in-front of the class it was prepended.
Keyword Arguments
Ruby 2.0 introduced first-class support for keyword arguments:
def foo(bar: ‘default’)
puts bar
end
foo # => ‘default’
foo(bar: ‘baz’) # => ‘baz’
Incremental GC
This will help to reduce memory consumption by Rails applications. Deprecated code removed and Cleanup
Action Mailer
#deliver and #deliver! methods have been removed, use new methods deliver_now or deliver_later.
*_path helper in email views has been removed and use *_url.
Active Record
Protected attributes(attr_accessible) completely unsupported now.
Unsupport for activerecord-deprecated_finders gem.
ActionPack Assertions
assert_template and assigns() assertions are deprecated and moved into its own gem rails-controller-testing.
ActiveRecord::Base#has_secure_token
Rails 5 has introduced has_secure_token to include random token in models.
Action View
In action view, helper methods such as content_tag_for and div_for were removed from the core and moved out to a separate gem record-tag-helper.
Turbolinks
New Turbolinks 3 solves one of the major problems of Rails. Few web apps works really slow cause it reloads the full page from server. This new Turbolinks 3 reloads only the contents of the body, it doesn’t reloads the whole page. It allows you to specify which elements to replace through partials.
Partial replacement feature, is the one of the most significant change in Rails 5. We will be able tell Turbolinks from client side that what content do we need to change/replace and what we don’t. To decide the replacement strategy in DOM, turbolinks will look for HTML5 custom attributes data-turbolinks-permanent and data-turbolinks-temporary.
We can use turbolinks.visit or Turbolinks.replace to update DOM and to trigger a replacement in the client side. Visit will issue a GET to the server to obtain the HTML that must be used to replace our DOM and replace expects from us the HTML that should be used for its operation.
The same functionalities can be triggered from the server-side with redirect_to and render, both redirect_to and render can receive change, keep and flush as options. But redirect_to can also receive turbolinks with true or false to force a redirect.
Action Cable
Action Cable is a framework, used to extend Rails via Websockets to add real-time message passing functionality. This is probably one of the best things in Rails 5. It smoothly integrates WebSockets with the rest of Rails application. Action cable makes it very easy to add realtime features to your app. The reason behind adding this feature was increasing need for such feature. It was introduced to extend Rails functionality with real time messaging utilizing WebSockets.
Action Cable offers a lot of advantages including being an open connection, extremely lightweight compared to other HTTP request. Another advantage is that once a connection made, it will remain open. Through that open line, both server and the client can communicate without reestablishing a new connection. The server and the client can use full-duplex connection of WebSocket to communicate to each other at the same time.
One disadvantage of Action Cable is its inability to cache requests. Another con of WebSocket is the support among browsers as only 70% of the browser market allows for WebSocket connections.
Additional New Features in Rails 5
- #or method in ActiveRecord::Relation
- #belongs_to is required by default
- Active Record Attribute API
- has_secure_token landed in ActiveRecord
- Mysql active record adapter gets Json support
- Render a template outside the controller
- Better Minitest Test Runner
Rails API
It allows you to generate API – only Rails app and cleans out all the middleware which is not necessary in an app. When you create a new Rails application using new rails API, you will get the configuration which assumes you are working with JSON not with HTML.
Command to Create Rails API Application:
rails new my-app-api –api
Render From Anywhere
All these days we have been using gems like render_anywhere to render views outside of controller. In Rails 5 you can render your views from anywhere. Along with the rendering options, there is also an option available for passing instant variables to templates.
Restart your App with a Rake Command
In Rail 5, you can restart all your apps with the command rake restart. And for migration: rails db:migrate
—
Major Features of Ruby on Rails
- Rails StrengthsRails is packed with features that make you more productive, with many of the following features building on one other.
- MetaprogrammingWhere other frameworks use extensive code generation from scratch, Rail framework uses Metaprogramming techniques to write programs. Ruby is one of the best languages for Metaprogramming, and Rails uses this capability well. Rails also uses code generation but relies much more on Metaprogramming for the heavy lifting.
- Active RecordRails introduces the Active Record framework, which saves objects into the database. The Rails version of the Active Record discovers the columns in a database schema and automatically attaches them to your domain objects using metaprogramming.
- Convention over configurationMost web development frameworks for .NET or Java force you to write pages of configuration code. If you follow the suggested naming conventions, Rails doesn’t need much configuration.
- ScaffoldingYou often create temporary code in the early stages of development to help get an application up quickly and see how major components work together. Rails automatically creates much of the scaffolding you’ll need.
- Built-in testingRails creates simple automated tests you can then extend. Rails also provides supporting code called harnesses and fixtures that make test cases easier to write and run. Ruby can then execute all your automated tests with the rake utility.
- Three environmentsRails gives you three default environments: development, testing, and production. Each behaves slightly differently, making your entire software development cycle easier. For example, Rails creates a fresh copy of the Test database for each test run.
- Full Stack Framework
- Includes everything needed to create a database-driven web application, using the Model-View-Controller pattern.
- Being a full-stack framework means all the layers are built to work seamlessly together with less code.
- Requires fewer lines of code than other frameworks.
- Convention over Configuration
- Rails shuns configuration files in favor of conventions, reflection, and dynamic runtime extensions.
- Your application code and your running database already contain everything that Rails needs to know!
AWS
Installation Instructions For Windows
A) Click the Windows “Start” button and select “All Programs” and then point to Ruby on Rails.
B) RDP Connection: To connect to the operating system,
1) Connect to virtual machine using following RDP credentials :
- Hostname: PublicDNS / IP of machine
- Port : 3389
Username: To connect to the operating system, use RDP and the username is Administrator.
Password : Please Click here to know how to get password .
C) Other Information:
1.Default installation path: will be on your root folder “C:\Ruby200-x64”
2.Default ports:
- Windows Machines: RDP Port – 3389
- Http: 80
- Https: 443
D) Notes : You need to install Any Database Software Listed in Window.
Configure custom inbound and outbound rules using this link
Installation Step by Step Screenshots
Videos