0% found this document useful (0 votes)
56 views28 pages

Ruby and Rails An Introduction: Karthiksr@cse - Iitb.ac - in

This document provides an introduction to Ruby and the Ruby on Rails framework. It discusses the Ruby programming language, describing it as dynamic, object-oriented, and platform independent. It then explains Rails as an open source web framework built on Ruby that follows the model-view-controller pattern. The document demonstrates Rails through examples and a sample application, covering concepts like models, views, controllers, databases, and testing. Resources for further learning about Ruby and Rails are also listed.

Uploaded by

Muhammed Ansar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views28 pages

Ruby and Rails An Introduction: Karthiksr@cse - Iitb.ac - in

This document provides an introduction to Ruby and the Ruby on Rails framework. It discusses the Ruby programming language, describing it as dynamic, object-oriented, and platform independent. It then explains Rails as an open source web framework built on Ruby that follows the model-view-controller pattern. The document demonstrates Rails through examples and a sample application, covering concepts like models, views, controllers, databases, and testing. Resources for further learning about Ruby and Rails are also listed.

Uploaded by

Muhammed Ansar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

Ruby and Rails

An Introduction

[email protected]
Agenda

The language – Ruby

The framework – Ruby On Rails

Demo

Resources

Questions
Ruby
SmallTalk

Lisp

RUBY Perl

Eiffel
Java
Ruby

Dynamic, Interpreted

Object oriented (True)

Scripting, RegExp

Platform independent

Lots of library support
Idioms

Principle of least surprise

Principle of succinctness

Principle of least effort

Convention

Extensible
Examples

puts "The obligatory hello world script"


More Examples
10.times do
puts Time.now.to_s
sleep 0.5
end
Examples - Blocks
def wish(to)
puts "Good Afternoon, #{to}"
end

["people", "friends", "all!"].each do |addressee|


wish addressee
end
Examples

ages = [15, 20, 30, 20, 10, 50, 35, 30]


puts ages.uniq.sort.reverse

puts ages - [30, 50]


Examples
class Rectangle

def initialize(l,b)
@length = l
@breadth = b
end

def area
@length * @breadth
end

def perimeter
2*(@length + @breadth)
end
end
Examples

rectangle = Rectangle.new(10,5)
puts rectangle.area
# prints 50
puts rectangle.perimeter
# prints 30
Rails in a nutshell

Web development that doesn't hurt

Open source web framework built in Ruby

Includes everything needed to create web apps
according to the Model-View-Control pattern

Opinionated software(!)

“Rails is the killer app for Ruby.”


Yukihiro Matsumoto, Creator of Ruby
Philosophy

DRY – “Don’t Repeat Yourself” – writing the same code
over and over again is a bad thing

Convention Over Configuration – Rails makes
assumptions about what you want to do and how you’re
going to do it, rather than letting you tweak every little thing
through endless configuration files.

The 80-20 Rule

REST is the best pattern for web apps – organizing your app
around resources and HTTP verbs is the fastest way to go.
Architecture
Components

Action Controller

Action View

Active Record

Action Mailer

Active Resource

Railties

Active Support
Demo
$ rails myblog
$ cd myblog
$ ./script/server
$ script/generate scaffold Post title:string content:text
$ rake db:migrate
$ ./script/server
CRUD, posts.xml
validates_presence_of :title, :content
validates_uniqueness_of :title
Demo
• File structure of a rails app
• MVC
• Database
• Code Walkthrough
Unit Testing
• Unit testing: rspec – BDD
Post.should have(:no).record
Post.create(“first”, “some contents”)
Post.create(“second”, “more contents”)
Post.should have(2).records
Integration Testing
new_session do |bob|
bob.goes_to_login
bob.goes_to_signup
bob.signs_up_with :name => "bob", :passwd =>”bob”
assert_response :success
end
Deployment

RAKE - Ruby’s Build System

WEBrick- Server is packaged with app

Preferred: Apache/mongrel

Environments: development, test, production
Development Environment
• Eclipse – RadRails
• NetBeans
• ...

Syntax highlighting, debuggers, autocomplete,


some amount of refactoring
Plugins

Very easy to write plugins

Think of reuse before writing any piece of
generic code

Most probably, someone has written a plugin

http://agilewebdevelopment.com/plugins
The Rails Community
The developer community around Rails is very
active, helpful and excited

Rails Wiki - http://wiki.rubyonrails.com/


Rails Mailing List – very active
Success Stories
• Twitter (http://www.twitter.com)
• Github (http://www.github.com)
• YellowPages (http://www.yellowpages.com)
• SlideShare (http://www.slideshare.net)
• Lots more! @
http://rubyonrails.org/applications
Resources - Ruby

http://www.ruby-lang.org

http://www.rubycentral.com/book

http://www.ruby-doc.org/
Resources - Rails

http://rubyonrails.org

http://guides.rubyonrails.org/

http://railsbrain.com/

http://railscasts.com
Questions?

[This ppt and code will be available at ~karthiksr]

You might also like