Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Ruby on Rails

Introduction to Ruby on Rails

Avatar for Vysakh Sreenivasan

Vysakh Sreenivasan

May 03, 2013
Tweet

More Decks by Vysakh Sreenivasan

Other Decks in Programming

Transcript

  1. Introduction to Ruby Table of Contents 1 Introduction to Ruby

    Why Ruby? Features Getting Started Installation 2 Introduction to Rails Why Rails? MVC Pattern Ruby utilities Installation REST 3 Notes Installation Tutorials Help Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 2 / 34
  2. Introduction to Ruby Why Ruby? Why Ruby? enjoy programming Vysakh

    Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 4 / 34
  3. Introduction to Ruby Why Ruby? Why Ruby? be productive enjoy

    programming Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 4 / 34
  4. Introduction to Ruby Why Ruby? Why Ruby? be productive enjoy

    programming be happy Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 4 / 34
  5. Introduction to Ruby Features HELLO WORLD #include<stdio.h> int main(){ printf(‘‘Hello

    World’’); return 0; } Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 5 / 34
  6. Introduction to Ruby Features HELLO WORLD import java.io.*; public class

    Example { public static void main(String[] args) { System.out.println(‘‘Hello World’’); } } Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 6 / 34
  7. Introduction to Ruby Features Simplicity Ruby puts ‘‘Hello World’’ Vysakh

    Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 7 / 34
  8. Introduction to Ruby Features Simplicity Ruby puts ‘‘Hello World’’ Vysakh

    Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 7 / 34
  9. Introduction to Ruby Features Easy to Learn Open Source Rich

    libraries Truly Object Oriented Less Coding with fewer bugs Helpful Community Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 8 / 34
  10. Introduction to Ruby Features Easy to Learn Open Source Rich

    libraries Truly Object Oriented Less Coding with fewer bugs Helpful Community Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 8 / 34
  11. Introduction to Ruby Features Easy to Learn Open Source Rich

    libraries Truly Object Oriented Less Coding with fewer bugs Helpful Community Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 8 / 34
  12. Introduction to Ruby Features Easy to Learn Open Source Rich

    libraries Truly Object Oriented Less Coding with fewer bugs Helpful Community Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 8 / 34
  13. Introduction to Ruby Features Easy to Learn Open Source Rich

    libraries Truly Object Oriented Less Coding with fewer bugs Helpful Community Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 8 / 34
  14. Introduction to Ruby Features Easy to Learn Open Source Rich

    libraries Truly Object Oriented Less Coding with fewer bugs Helpful Community Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 8 / 34
  15. Introduction to Ruby Getting Started Interactive Ruby Simple Syntax Variables

    Naming Convention Constants Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 9 / 34
  16. Introduction to Ruby Getting Started Interactive Ruby Simple Syntax Variables

    Naming Convention Constants Type small bits of ruby code, see it get executed Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 9 / 34
  17. Introduction to Ruby Getting Started Interactive Ruby Simple Syntax Variables

    Naming Convention Constants Parenthesis, Braces, Tab spaces- Optional Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 9 / 34
  18. Introduction to Ruby Getting Started Interactive Ruby Simple Syntax Variables

    Naming Convention Constants a = 5 b = 10 c = a + b d = 11.4 word = ‘‘Cool :)’’ Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 9 / 34
  19. Introduction to Ruby Getting Started Interactive Ruby Simple Syntax Variables

    Naming Convention Constants Camel Case firstName = “vysakh” first_name=‘‘Vysakh’’ Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 9 / 34
  20. Introduction to Ruby Getting Started Interactive Ruby Simple Syntax Variables

    Naming Convention Constants Pi = 3.14 #Constants begin with Capital Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 9 / 34
  21. Introduction to Ruby Getting Started In Ruby, everything is Vysakh

    Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 10 / 34
  22. Introduction to Ruby Getting Started Logical Operators Loops List Hash

    and Sybmols Functions Classes if 1 == 1 puts ‘‘1 is equal to 1’’ elsif 1 != 1 puts ‘‘1 is not equal to 1’’ else puts ’’Something else‘‘ end Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 11 / 34
  23. Introduction to Ruby Getting Started Logical Operators Loops List Hash

    and Sybmols Functions Classes for while times upto downto step until Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 11 / 34
  24. Introduction to Ruby Getting Started Logical Operators Loops List Hash

    and Sybmols Functions Classes numbers = [1, 3, 55, 2999] fruits = [’’Mango‘‘, ’’Apple‘‘] mixed = [1, ’’Mango‘‘] Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 11 / 34
  25. Introduction to Ruby Getting Started Logical Operators Loops List Hash

    and Sybmols Functions Classes names = {’’first‘‘ => ’’Mark‘‘} #Strings are expensive # ‘‘first’’ is a string # :first is a symbol names = {:first => ’’Mark‘‘} Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 11 / 34
  26. Introduction to Ruby Getting Started Logical Operators Loops List Hash

    and Sybmols Functions Classes def add a, b a+b end puts add 1, 2 Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 11 / 34
  27. Introduction to Ruby Getting Started Logical Operators Loops List Hash

    and Sybmols Functions Classes class Calc def add a, b a+b end end class ChildCalc < Calc end c = Calc.new puts c.add 4, 5 child = ChildCalc.new puts child.add 3, 4 Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 11 / 34
  28. Introduction to Ruby Installation Installation Use Ruby Version Management Tool

    Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 12 / 34
  29. Introduction to Ruby Installation Installation Use Ruby Version Management Tool

    RVM or rbenv Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 12 / 34
  30. Introduction to Rails Table of Contents 1 Introduction to Ruby

    Why Ruby? Features Getting Started Installation 2 Introduction to Rails Why Rails? MVC Pattern Ruby utilities Installation REST 3 Notes Installation Tutorials Help Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 13 / 34
  31. Introduction to Rails Why Rails? Why Rails? Extremely Productive Web

    Framework Develop 10 times faster than a Java Framework Rails promotes best practises Rails is very mature web framework Open Source, Vibrant Community Access to hundreds of gems Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 15 / 34
  32. Introduction to Rails Why Rails? Why Rails? Extremely Productive Web

    Framework Develop 10 times faster than a Java Framework Rails promotes best practises Rails is very mature web framework Open Source, Vibrant Community Access to hundreds of gems Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 15 / 34
  33. Introduction to Rails Why Rails? Why Rails? Extremely Productive Web

    Framework Develop 10 times faster than a Java Framework Rails promotes best practises Rails is very mature web framework Open Source, Vibrant Community Access to hundreds of gems Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 15 / 34
  34. Introduction to Rails Why Rails? Why Rails? Extremely Productive Web

    Framework Develop 10 times faster than a Java Framework Rails promotes best practises Rails is very mature web framework Open Source, Vibrant Community Access to hundreds of gems Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 15 / 34
  35. Introduction to Rails Why Rails? Why Rails? Extremely Productive Web

    Framework Develop 10 times faster than a Java Framework Rails promotes best practises Rails is very mature web framework Open Source, Vibrant Community Access to hundreds of gems Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 15 / 34
  36. Introduction to Rails Why Rails? Why Rails? Extremely Productive Web

    Framework Develop 10 times faster than a Java Framework Rails promotes best practises Rails is very mature web framework Open Source, Vibrant Community Access to hundreds of gems Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 15 / 34
  37. Introduction to Rails Why Rails? Rails Philosophy Convention over Configuration

    Donot Repeat Yourself (DRY) REST is the best pattern for web applications Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 16 / 34
  38. Introduction to Rails Why Rails? Rails Philosophy Convention over Configuration

    Donot Repeat Yourself (DRY) REST is the best pattern for web applications Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 16 / 34
  39. Introduction to Rails Why Rails? Rails Philosophy Convention over Configuration

    Donot Repeat Yourself (DRY) REST is the best pattern for web applications Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 16 / 34
  40. Introduction to Rails Why Rails? FULL STACK FRAMEWORK.. WHAT?? It

    abstracts and manages all parts of a web application Database(model) HTML/visualization(view) Request flow(Controller) Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 17 / 34
  41. Introduction to Rails Why Rails? FULL STACK FRAMEWORK.. WHAT?? It

    abstracts and manages all parts of a web application Database(model) HTML/visualization(view) Request flow(Controller) Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 17 / 34
  42. Introduction to Rails Why Rails? FULL STACK FRAMEWORK.. WHAT?? It

    abstracts and manages all parts of a web application Database(model) HTML/visualization(view) Request flow(Controller) Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 17 / 34
  43. Introduction to Rails MVC Pattern MVC Pattern Vysakh Sreenivasan (vysakh.quora.com)

    Web Development using Ruby on Rails March 24, 2013 18 / 34
  44. Introduction to Rails MVC Pattern Model Maps a table in

    the database with a ruby object Validates your data before saving them Here you manipulate your data Here you add associations Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 19 / 34
  45. Introduction to Rails MVC Pattern Model Maps a table in

    the database with a ruby object Validates your data before saving them Here you manipulate your data Here you add associations Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 19 / 34
  46. Introduction to Rails MVC Pattern Model Maps a table in

    the database with a ruby object Validates your data before saving them Here you manipulate your data Here you add associations Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 19 / 34
  47. Introduction to Rails MVC Pattern Model Maps a table in

    the database with a ruby object Validates your data before saving them Here you manipulate your data Here you add associations Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 19 / 34
  48. Introduction to Rails MVC Pattern Controller Each method is a

    function that your application exposes Controls the flow of the request Exposes your data to views Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 20 / 34
  49. Introduction to Rails MVC Pattern Controller Each method is a

    function that your application exposes Controls the flow of the request Exposes your data to views Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 20 / 34
  50. Introduction to Rails MVC Pattern Controller Each method is a

    function that your application exposes Controls the flow of the request Exposes your data to views Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 20 / 34
  51. Introduction to Rails MVC Pattern Views Show data to the

    user (in various format: html, csv, pdf..) Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 21 / 34
  52. Introduction to Rails MVC Pattern Routes It is a map

    between the HTTP request and the method of a controller Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 22 / 34
  53. Introduction to Rails MVC Pattern Migration add column/remove column rename

    column/rename table change column create table/drop table Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 23 / 34
  54. Introduction to Rails Ruby utilities Rake Rake a simple ruby

    build program with capabilities similar to make. Create a file Rakefile namespace :my do task :alarm do puts ‘‘Turned off alarm.’’ end end Run this rake file with the command rake my:alarm Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 24 / 34
  55. Introduction to Rails Ruby utilities gem and bundler gem A

    RubyGem is a software package, commonly called a gem. Gems contain a packaged Ruby application or library. bundler Bundler is the way to manage gem dependencies in Rails Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 25 / 34
  56. Introduction to Rails Installation Installation and Creation Installing gem install

    rails Creation rails new project Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 26 / 34
  57. Introduction to Rails REST What is REST? Vysakh Sreenivasan (vysakh.quora.com)

    Web Development using Ruby on Rails March 24, 2013 27 / 34
  58. Introduction to Rails REST Representational State transfer REST in terms

    of Rails boils down to two main principles: Using resource identifiers such as URLs to represent resources. Transferring representations of the state of that resource between system components. Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 28 / 34
  59. Introduction to Rails REST Rest - Example For example, the

    following HTTP request: DELETE /photos/17 would be understood to refer to a photo resource with the ID of 17, and to indicate a desired action: deleting that resource. In config/routes file resources :photos In controller class PhotosController < ApplicationController def destroy end end Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 29 / 34
  60. Notes Table of Contents 1 Introduction to Ruby Why Ruby?

    Features Getting Started Installation 2 Introduction to Rails Why Rails? MVC Pattern Ruby utilities Installation REST 3 Notes Installation Tutorials Help Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 30 / 34
  61. Notes Installation Installation rbenv https://github.com/sstephenson/rbenv RVM http://beginrescueend.com/ Windows http://railsinstaller.org/ Mac

    http://mxcl.github.com/homebrew/ Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 31 / 34
  62. Notes Tutorials Tutorials Ruby http://tryruby.org/ Rails Getting Started with Rails

    http: //guides.rubyonrails.org/getting_started.html Michael Hartl’s Book http: //guides.rubyonrails.org/getting_started.html Rails Zombies http://railsforzombies.com/ Rails Reference Railscasts http://railscasts.com/ Vysakh Sreenivasan (vysakh.quora.com) Web Development using Ruby on Rails March 24, 2013 32 / 34