Introduction to Ruby on Rails

27
RUBY ON RAILS MITHUN SASIDHARAN Web Evangelist & Foss Enthusiast

description

The presentation gives an overview about the ruby programming language and Rails, the web framework built over it ruby. It does highlight some of the key features of ruby programming language and mentions the key benefits of using Rails framework for web application development.

Transcript of Introduction to Ruby on Rails

Page 1: Introduction to Ruby on Rails

RUBY ON RAILS

MITHUN SASIDHARANWeb Evangelist & Foss Enthusiast

Page 2: Introduction to Ruby on Rails

CONTENTS

INTRODUCTION

What is Ruby?

Java Vs Ruby

What is Rails?

Ruby on Rails

Conclusion

Page 3: Introduction to Ruby on Rails

INTRODUCTION

Ruby on Rails, sometimes known as "RoR" or just 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.

Page 4: Introduction to Ruby on Rails

Now, what’s a web application ??

A web application is an application that is accessed via web browser over a network such as the Internet or an intranet. The web Application consists of a browser, an application and a database.

The browser makes a request to the web application, which then interacts with the database, and produce suitable output and sends it back to the browser.

Page 5: Introduction to Ruby on Rails

WHAt’s RUBY ?

Ruby is a dynamic, reflective, general purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features.

Ruby originated in Japan during the mid-1990s and was initially developed and designed by Yukihiro "Matz" Matsumoto. It is based on Perl, Smalltalk, Eiffel, Ada, and Lisp.

Ruby supports multiple programming paradigms, including functional, object oriented, imperative and reflective. It is similar in varying respects to Python, Perl, Lisp, Dylan, and CLU.

Page 6: Introduction to Ruby on Rails

FEATURES OF RUBY !!

Objects everywhere! - In Ruby everything is an object including simple numeric values. Here is an example,

Blocks - Blocks is a powerful feature in Ruby which simplifies programming. Blocks are code blocks which can be passed as a parameter to a method. Using this feature it is easy to build code libraries which can delegate varying functionality to code blocks to be built later.

Implicit return value in methods - Value of the last expression in a method becomes the return value of the method. In Ruby return keyword is optional.

Page 7: Introduction to Ruby on Rails

In Ruby everything is open! - In Ruby you can easily extend classes and modules. This means that nothing in Ruby (including built in classes and modules) are closed!. Interestingly additional methods can be added to a class even at runtime.

Ruby supports parallel assignment - It is possible to change multiple variables in a single assignment. The best example is the swapping of two variable.

In Ruby strings are mutable - In Ruby it is possible to change a string variable in place. Hence unlike Java, the same string literal when used multiple times will point to different object instances.

True and false in Ruby - In Ruby only nil and false evaluate to false. This means that everything else evaluates to true! Hence even the value 0 evaluate to true in ruby.

Page 8: Introduction to Ruby on Rails

SIMPLE RUBY PROGRAM TO ADD TWO NUMBERS

# define a function called addtwo with two parameters

def addtwo(a, b)

a + b; # return a + b

end  

print "Please enter number 1 : "; # get the input from the console, val1 = gets;

print "Please enter number 2 : "; val2 = gets;

# convert the string console inputs to_i (to_integers) and add together print "Answer : " , (val1.to_i + val2.to_i), "\n";

Page 9: Introduction to Ruby on Rails

Java Vs ruby !!

•Ruby is interpreted, Java is compiled (before being interpreted)

>ruby my_program.rb >javac MyProgram.java >java MyProgram

• Code can be loaded at runtime

• Code is easily accessible

• Speed performance issues

Page 10: Introduction to Ruby on Rails

Ruby use dynamic typing

• Values have type, variables not

• Decrease language complexity

- No type declaration- No type casting• Increase flexibility

• Errors appears at run-time

Page 11: Introduction to Ruby on Rails

Ruby syntax is terse

Page 12: Introduction to Ruby on Rails

Ruby Supports Concept of Blocks

Page 13: Introduction to Ruby on Rails

JAVA WIN ON PERFORMANCE FIELD

Page 14: Introduction to Ruby on Rails

On a Business Point of View ! !

• Java is a well-known technology

• Lots of developments have been made with it

• Easy to find experts

• Still not that much available Ruby developers

Page 15: Introduction to Ruby on Rails

YET, RUBY PICKING UP MOMENTUM !!

Page 16: Introduction to Ruby on Rails

WHAT IS RAILS ??

Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Control pattern.

Ruby on Rails was extracted by David Heinemeier Hansson from his work on Basecamp, a project management tool by 37signals (now a web application company).

Like many contemporary web frameworks, Rails uses the Model-View-Controller (MVC) architecture pattern to organize application programming.

Page 17: Introduction to Ruby on Rails

WHAT IS A WEB FRAMEWORK ?? A web application framework is a software framework that is designed to support the development of dynamic websites, Web applications and Web services. The framework aims to alleviate the overhead associated with common activities performed in Web development.

For example, many frameworks provide libraries for database access, templating frameworks and session management, and often promote code reuse.

Some of the main features of web framework is that they provide security,database access and mapping,URL mapping,Web template system,caching,AJAX ,Automatic Configurations and so on.

Page 18: Introduction to Ruby on Rails

MVC ARCHITECTURE

Model–view–controller (MVC) is an architectural pattern used in software engineering. The pattern isolates business logic from input and presentation, permitting independent development, testing and maintenance of each.

These frameworks use actions that do the required processing, and then "push" the data to the view layer to render the results. These frameworks start with the view layer, which can then "pull" results from multiple controllers as needed.

Page 19: Introduction to Ruby on Rails

MODEL- Used for persistence and relationships.

VIEW- Used for displaying the data.

CONTROLLER- The logic of the application.

Page 20: Introduction to Ruby on Rails

FEATURES OF RUBY ON RAILS

Ruby on Rails is separated into various packages, namely ActiveRecord(an object-relational mapping system for database access), ActiveResource (provides web services), ActionPack , ActiveSupport and ActionMailer.

Prior to version 2.0, Rails also included the Action Web Service package which is now replaced by Active Resource.

Apart from standard packages, developers can make plugins to extend existing packages.

Page 21: Introduction to Ruby on Rails

RAILS VS C#/.NET

Page 22: Introduction to Ruby on Rails

RAILS VS J2EE

Both have a learning curve.

RAILS has the edge in productivity by a significant margin.

J2EE currently has an edge in scalability. If it’s a client facing system for millions of concurrent users – use J2EE.

If it’s an internal web application, definitely take a look at this technology as a possible way of shortcutting the long development time for a J2EE web application.

Page 23: Introduction to Ruby on Rails

Or another way to put it ……

Page 24: Introduction to Ruby on Rails

APPLICATIONS OF RoR !!

Ruby On Rails have been in use now by over 500 websites.

Some of the leading websites using RoR are 43things.com, yellowpages.com, lumosity.com and so on.

Ruby on Rails is Picking up the pace and have become more and more viable in the business scenario.

Page 25: Introduction to Ruby on Rails

CONCLUSION

RoR an evolving Toolset.

Ruby is what makes Rails special, the interest in general Ruby programming will continue to expand rapidly

RoR can be best used for small web based applications requring parallel development.

Page 26: Introduction to Ruby on Rails

REFERENCEwww.rubyonrails.org

www.wikipedia.org

www.37signals.com

The Rails Way- OBIE FERNANDEZ

From Java To Ruby – BRUCE TATE

Page 27: Introduction to Ruby on Rails

THANK YOU !!