0
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 ...
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 g...
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
e...
Exercise 2
- Create an array of marks you got in your
last assessment.
- Find if the sum of odd numbers is greater
than th...
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 ...
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
...
Class
class Sports
def initialize(players, name)
@no_of_players = players
@name = name
end
end
cricket = Sports.new(11, “Cricket...
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
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Ruby on Rails for beginners
Upcoming SlideShare
Loading in...5
×

Ruby on Rails for beginners

4,751

Published on

Introduction to Ruby and Introduction to Ruby on Rails basic concepts for beginners. The google presentation is even better in full screen https://docs.google.com/presentation/d/1EE0VuB_PkD2-8j5JNs6CUQHb4J9ToIgC7-IxYTojiS0/pub?start=false&loop=false&delayms=3000#slide=id.p

Published in: Software, Technology
1 Comment
24 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,751
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
195
Comments
1
Likes
24
Embeds 0
No embeds

No notes for slide

Transcript of "Ruby on Rails for beginners"

  1. 1. I am Vysakh. I am a web developer.
  2. 2. In Ruby puts “Hello world”
  3. 3. Ruby is simply simple Just like english
  4. 4. Variables
  5. 5. You have - basket A with 10 apples - basket B with 20 apples. Find the sum and difference
  6. 6. basketa = 10 apples basketb = 20 apples sum = basketa + basketb => 10 + 20 = 30 difference = basketb - basketa => 20 - 10 = 10
  7. 7. basket_a = 10 basket_b = 20 sum = basket_a + basket_b difference = basket_b - basket_a In Ruby
  8. 8. It is just like what you wrote in your kindergarden answer sheet
  9. 9. Creator of Ruby - Matz
  10. 10. Running the code
  11. 11. Ruby is executed line by line So output of a single line/logic can be seen using irb
  12. 12. Opening up irb in the terminal Instead of executing as a program file. Useful for learning, debugging.
  13. 13. Conditionals
  14. 14. cold_weather = true if cold_weather puts “Wear something warm” else puts “Don’t wear something” end Ruby code
  15. 15. Most thing in Ruby is Object
  16. 16. 2.odd?() => false “Vysakh”.length() => 6
  17. 17. Brackets are optional in Ruby 2.odd? => false “Vysakh”.length => 6
  18. 18. 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.
  19. 19. Array/List
  20. 20. In Ruby shopping = [ “milk”, “cheese”, “olive oil”]
  21. 21. Loops
  22. 22. In Ruby 20.times do puts “I must do my homework” end
  23. 23. Also, there are - loop - while loop - for loop - step - upto
  24. 24. HAPPY Ruby is all about making programmer
  25. 25. Mam, please take each item for me to bill
  26. 26. cart = [“biscuit”, milk”, “shampoo”, “tampons” ]
  27. 27. Mam, please take each item for me to bill cart = [“biscuit”, milk”, “shampoo”, “tampons” ] cart.each do |item| puts item end
  28. 28. 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
  29. 29. HASH
  30. 30. In Ruby slang = { “lol” => “laugh out loud”, “brb” => “Be right back” } slang[“lol”] => laught out loud
  31. 31. Use symbols instead of string slang = { :lol => “laugh out loud”, :brb => “Be right back” } slang[:lol] => laught out loud
  32. 32. Symbols in Ruby :hand.class => Symbol
  33. 33. Alternate way to write hash slang = { lol: “laugh out loud”, brb: “Be right back” } slang[:lol] => laught out loud
  34. 34. 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
  35. 35. Functions
  36. 36. In Ruby def y(x) x**3 end y(3) # => 27 y(2) # => 8
  37. 37. 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
  38. 38. Class
  39. 39. 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”)
  40. 40. Inheritance
  41. 41. a version manager (RVM or rbenv or other) Install ruby using
  42. 42. rbenv Installing Ruby using
  43. 43. Installing and setting Ruby
  44. 44. dhh Creator of Ruby on Rails
  45. 45. Installing Rails
  46. 46. Creating a new rails project
  47. 47. Files generated with “rails new myproject” command
  48. 48. Starting Rails server
  49. 49. Check the browser localhost:3000
  50. 50. Understanding Rails
  51. 51. A dress shop Pant section? 1st floor kid. 2nd section
  52. 52. 1st floor here is your pant
  53. 53. A Rails server /about routes.rb home controller, about action
  54. 54. A Rails server home controller, about action here is your html file
  55. 55. Lets do it in Rails
  56. 56. filename: config/routes.rb Configure the routes to get /about
  57. 57. The corresponding html
  58. 58. and go to ‘/about’ url Lets open the browser
  59. 59. available in the section? When the pant is not Coming back to the kid and pant story
  60. 60. 1st floor I want this specific design Godown Oh kid lemme go to the godown and get
  61. 61. In Rails Database home controller, about action /posts/1
  62. 62. and have an abstraction(model) Lets create a table
  63. 63. This will create model, migration files
  64. 64. migration - A ruby file that will create, modify tables posts table title column of type string
  65. 65. from the ruby file(migration) Lets create the tables
  66. 66. Rake, a simple ruby build program with capabilities similar to make This creates the posts table
  67. 67. table records through Rails model Lets create, manipulate
  68. 68. Post is a Ruby class that Inherits ActiveRecord app/models/post.rb
  69. 69. Object Relation Mapping(ORM) layer Active Record is an
  70. 70. tables map to classes,
  71. 71. rows map to objects rows map to objects Rows map to objects Columns map to object attributes
  72. 72. Few operations
  73. 73. Lets use this query in Rails controller and give it to the user
  74. 74. Configure the routes file
  75. 75. Open up the browser
  76. 76. Show the title, description in html app/views/show.html.erb
  77. 77. Now lets check the browser
  78. 78. Now lets do all this in one command -> scaffold
  79. 79. This will generate all files based on REST Architecture
  80. 80. Guides and resources
  81. 81. http://tryruby.org http://www.codecademy.com/en/tracks/ruby http://ruby.learncodethehardway.org/book/ Ruby
  82. 82. Ruby on Rails railstutorial.org/book railsforzombies.org guides.rubyonrails.org/getting_started railscasts.com
  83. 83. Local Ruby Community - chennair.b Mailing list - google groups Meetups - www.meetup.com/chennai-ruby
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×