SlideShare a Scribd company logo
1 of 106
Download to read offline
I am Vysakh.
I am a web developer.
In Ruby
puts โ€œHello worldโ€
Ruby is simply simple
Just like english
Variables
You have
- basket A with 10 apples
- basket B with 20 apples.
Find the sum and
difference
basketa = 10 apples
basketb = 20 apples
sum = basketa + basketb
=> 10 + 20 = 30
difference = basketb - basketa
=> 20 - 10 = 10
basket_a = 10
basket_b = 20
sum = basket_a + basket_b
difference = basket_b - basket_a
In Ruby
It is just like what you wrote in your
kindergarden answer sheet
Creator of Ruby - Matz
Running the code
Ruby is executed line by line
So output of a single line/logic can be seen
using irb
Opening up irb in the terminal
Instead of executing as a program file. Useful
for learning, debugging.
Conditionals
cold_weather = true
if cold_weather
puts โ€œWear something warmโ€
else
puts โ€œDonโ€™t wear somethingโ€
end
Ruby code
Most thing in Ruby is Object
2.odd?()
=> false
โ€œVysakhโ€.length()
=> 6
Brackets are optional in Ruby
2.odd?
=> false
โ€œVysakhโ€.length
=> 6
Exercise 1
a) Get a string and check if it is palindrome.
b) Get a number and print the reverse of it.
Hint: use gets to get the input.
Array/List
In Ruby
shopping = [ โ€œmilkโ€, โ€œcheeseโ€, โ€œolive oilโ€]
Loops
In Ruby
20.times do
puts โ€œI must do my homeworkโ€
end
Also, there are
- loop
- while loop
- for loop
- step
- upto
HAPPY
Ruby is all about making programmer
Mam, please take
each item for me to
bill
cart = [โ€œbiscuitโ€, milkโ€, โ€œshampooโ€, โ€œtamponsโ€ ]
Mam, please take
each item for me to
bill
cart = [โ€œbiscuitโ€, milkโ€, โ€œshampooโ€, โ€œtamponsโ€ ]
cart.each do |item|
puts item
end
Exercise 2
- Create an array of marks you got in your
last assessment.
- Find if the sum of odd numbers is greater
than the sum of even numbers, if it is, you
have big odds at passing.
- Pass this information or bad luck will follow
HASH
In Ruby
slang = {
โ€œlolโ€ => โ€œlaugh out loudโ€,
โ€œbrbโ€ => โ€œBe right backโ€
}
slang[โ€œlolโ€]
=> laught out loud
Use symbols instead of string
slang = {
:lol => โ€œlaugh out loudโ€,
:brb => โ€œBe right backโ€
}
slang[:lol]
=> laught out loud
Symbols in Ruby
:hand.class
=> Symbol
Alternate way to write hash
slang = {
lol: โ€œlaugh out loudโ€,
brb: โ€œBe right backโ€
}
slang[:lol]
=> laught out loud
Exercise 3
- Create a list of ipl team hashes
- with batsmen (3) name as key and their
sixes as values.
a) Find the sixes hit by a batsmen of a given
name
Functions
In Ruby
def y(x)
x**3
end
y(3) # => 27
y(2) # => 8
Exercise 4
a) Create a method rajini_style. Return his
dialogue (your favorite).
b) Create a factorial method that gets a
number and returns the factorial
Class
class Sports
def initialize(players, name)
@no_of_players = players
@name = name
end
end
cricket = Sports.new(11, โ€œCricketโ€)
foot_ball = Sports.new(11, โ€œFootballโ€)
Inheritance
a version manager (RVM or rbenv or other)
Install ruby using
rbenv
Installing Ruby using
Installing and setting Ruby
dhh
Creator of Ruby on Rails
Installing Rails
Creating a new rails project
Files generated with โ€œrails new
myprojectโ€ command
Starting Rails server
Check the browser
localhost:3000
Understanding Rails
A dress shop
Pant
section?
1st floor
kid. 2nd
section
1st floor
here is
your pant
A Rails server
/about
routes.rb
home
controller,
about
action
A Rails server
home controller,
about action
here is
your html
file
Lets do it in Rails
filename: config/routes.rb
Configure the routes to get /about
The corresponding html
and go to โ€˜/aboutโ€™ url
Lets open the browser
available in the section?
When the pant is not
Coming back to the kid and pant story
1st floor
I want this
specific
design
Godown
Oh kid
lemme go
to the
godown
and get
In Rails
Database
home controller,
about action
/posts/1
and have an abstraction(model)
Lets create a table
This will create model,
migration files
migration - A ruby file that will create, modify
tables
posts table
title column of type
string
from the ruby file(migration)
Lets create the tables
Rake, a simple ruby build program with
capabilities similar to make
This creates the posts table
table records through Rails model
Lets create, manipulate
Post is a Ruby class that Inherits ActiveRecord
app/models/post.rb
Object Relation Mapping(ORM) layer
Active Record is an
tables map to classes,
rows map to objects
rows map to objects
Rows map to objects
Columns map to object attributes
Few operations
Lets use this query in
Rails controller and give it to the user
Configure the routes file
Open up the browser
Show the title, description in html
app/views/show.html.erb
Now lets check the browser
Now lets do all this in
one command -> scaffold
This will generate all files
based on REST Architecture
Guides and resources
http://tryruby.org
http://www.codecademy.com/en/tracks/ruby
http://ruby.learncodethehardway.org/book/
Ruby
Ruby on Rails
railstutorial.org/book
railsforzombies.org
guides.rubyonrails.org/getting_started
railscasts.com
Local Ruby Community - chennair.b
Mailing list - google groups
Meetups - www.meetup.com/chennai-ruby
Ruby on Rails for beginners

More Related Content

What's hot

Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
Eddie Kao
ย 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
ย 
Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹
Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹
Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹
Wen-Tien Chang
ย 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
Wen-Tien Chang
ย 

What's hot (20)

Let's Learn Ruby - Basic
Let's Learn Ruby - BasicLet's Learn Ruby - Basic
Let's Learn Ruby - Basic
ย 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
ย 
Ruby
RubyRuby
Ruby
ย 
Ruby for Java Developers
Ruby for Java DevelopersRuby for Java Developers
Ruby for Java Developers
ย 
Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
ย 
Introduction to Ruby
Introduction to RubyIntroduction to Ruby
Introduction to Ruby
ย 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
ย 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
ย 
Coffee Script
Coffee ScriptCoffee Script
Coffee Script
ย 
Learn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a RescueLearn Ruby 2011 - Session 5 - Looking for a Rescue
Learn Ruby 2011 - Session 5 - Looking for a Rescue
ย 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
ย 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
ย 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails Basics
ย 
Ruby: Beyond the Basics
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the Basics
ย 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
ย 
A tour on ruby and friends
A tour on ruby and friendsA tour on ruby and friends
A tour on ruby and friends
ย 
JavaScript Essentials for Ember development
JavaScript Essentials for Ember developmentJavaScript Essentials for Ember development
JavaScript Essentials for Ember development
ย 
Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹
Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹
Ruby ๅ…ฅ้–€ ็ฌฌไธ€ๆฌกๅฐฑไธŠๆ‰‹
ย 
Distributed Ruby and Rails
Distributed Ruby and RailsDistributed Ruby and Rails
Distributed Ruby and Rails
ย 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
ย 

Similar to Ruby on Rails for beginners

Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Manoj Kumar
ย 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
PatchSpace Ltd
ย 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Raimonds Simanovskis
ย 
Carlosbrando Rubyonrails21 En
Carlosbrando Rubyonrails21 EnCarlosbrando Rubyonrails21 En
Carlosbrando Rubyonrails21 En
Casey Bradford
ย 

Similar to Ruby on Rails for beginners (20)

Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
ย 
Ruby Gotchas
Ruby GotchasRuby Gotchas
Ruby Gotchas
ย 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
ย 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
ย 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
ย 
Ruby
RubyRuby
Ruby
ย 
Playfulness at Work
Playfulness at WorkPlayfulness at Work
Playfulness at Work
ย 
Uses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & StubsUses & Abuses of Mocks & Stubs
Uses & Abuses of Mocks & Stubs
ย 
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
What's new and great in Rails 3 - Matt Gauger - Milwaukee Ruby Users Group De...
ย 
Threequals - Case Equality in Ruby
Threequals - Case Equality in RubyThreequals - Case Equality in Ruby
Threequals - Case Equality in Ruby
ย 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
ย 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
ย 
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and JasmineRails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript using CoffeeScript, Backbone.js and Jasmine
ย 
Fewd week5 slides
Fewd week5 slidesFewd week5 slides
Fewd week5 slides
ย 
lab4_php
lab4_phplab4_php
lab4_php
ย 
lab4_php
lab4_phplab4_php
lab4_php
ย 
Ruby Gotchas
Ruby GotchasRuby Gotchas
Ruby Gotchas
ย 
Ruby Programming Language - Introduction
Ruby Programming Language - IntroductionRuby Programming Language - Introduction
Ruby Programming Language - Introduction
ย 
Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2Code for Startup MVP (Ruby on Rails) Session 2
Code for Startup MVP (Ruby on Rails) Session 2
ย 
Carlosbrando Rubyonrails21 En
Carlosbrando Rubyonrails21 EnCarlosbrando Rubyonrails21 En
Carlosbrando Rubyonrails21 En
ย 

More from Vysakh Sreenivasan (7)

Caching in rails
Caching in railsCaching in rails
Caching in rails
ย 
Introduction to Vim, the text editor
Introduction to Vim, the text editorIntroduction to Vim, the text editor
Introduction to Vim, the text editor
ย 
Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)Testing Ruby with Rspec (a beginner's guide)
Testing Ruby with Rspec (a beginner's guide)
ย 
A limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced RubyA limited guide to intermediate and advanced Ruby
A limited guide to intermediate and advanced Ruby
ย 
What's new in Rails 4.1
What's new in Rails 4.1What's new in Rails 4.1
What's new in Rails 4.1
ย 
Building Rich Ruby on Rails with Emberjs
Building Rich Ruby on Rails with EmberjsBuilding Rich Ruby on Rails with Emberjs
Building Rich Ruby on Rails with Emberjs
ย 
Introduction to vim
Introduction to vimIntroduction to vim
Introduction to vim
ย 

Recently uploaded

CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
anilsa9823
ย 

Recently uploaded (20)

5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
ย 
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spacesย - and Epistemic Querying of RDF-...
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
ย 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
ย 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
ย 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
ย 
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS LiveVip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida โžก๏ธ Delhi โžก๏ธ 9999965857 No Advance 24HRS Live
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
ย 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlanโ€™s ...
ย 

Ruby on Rails for beginners