Rails for PHP Developers

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    I’m the CEO and Founder of ADS, an Orlando based company that builds custom web and iPhone applications, and helps software companies implement Agile practices

    We have three apps that we develop

    Discount code for an additional free month

    We help connect freelancers and small business people with each other

    You can find us all over the Internet

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    A little about me
    I cuss, a lot - if easily offended, Denis Leary: get a fucking helmet
    What about you? Who here is a PHP developer? Who here has messed around with Rails?

    This talk is based off the information presented in Rails for PHP Developers by Derek DeVries and Mike Naberezny
    I’ll be giving away a copy at the end of this talk

    I’m not here to convert you.
    This is not a this or that choice.

    As developers we have many tools to choose from.
    Rails is another tool we can use to build web apps.

    IMO, it’s easiest to learn Rails coming from PHP
    In fact, I was a php developer before moving to Rails
    The good news: there are a lot of similarities, which we’ll see
    To be a good Rails programmer, you need to know Ruby

    Highly flexible, which means that you can easily fuck it up

    Highly flexible, which means that you can easily fuck it up

    Highly flexible, which means that you can easily fuck it up

    Highly flexible, which means that you can easily fuck it up

    Highly flexible, which means that you can easily fuck it up

    Let’s dig into the specifics

    MVC like Rails

    So without further ado, let’s dig in.

    So without further ado, let’s dig in.

    in_array(value, array)
    array_push(array, value)

    in_array(value, array)
    array_push(array, value)

    Going back to the idea that everything in Ruby is an object, here’s an example.

    $a has the one value, and $b is empty
    All assignments here are by value

    $a has the one value, and $b is empty
    All assignments here are by value

    $a has the one value, and $b is empty
    All assignments here are by value

    $a has the one value, and $b is empty
    All assignments here are by value

    $a has the one value, and $b is empty
    All assignments here are by value

    In Ruby, both a and b contain a reference to the same Hash object
    In Ruby, the assignment always assigns by reference - big difference

    In Ruby, both a and b contain a reference to the same Hash object
    In Ruby, the assignment always assigns by reference - big difference

    In Ruby, both a and b contain a reference to the same Hash object
    In Ruby, the assignment always assigns by reference - big difference

    In Ruby, both a and b contain a reference to the same Hash object
    In Ruby, the assignment always assigns by reference - big difference

    In Ruby, both a and b contain a reference to the same Hash object
    In Ruby, the assignment always assigns by reference - big difference

    Methods on a and b are acting on the same object

    Methods on a and b are acting on the same object

    Methods on a and b are acting on the same object

    Methods on a and b are acting on the same object

    Methods on a and b are acting on the same object

    To help us look at methods, we turn to our friend the monkey

    Some are small, some look really cool.
    But all monkeys throw things.

    Pass in a single param

    Param (fruit) is optional

    Multiple params, set a default value
    You might get the fruit, but you have 100% chance of getting the feces

    Basic method declaration and optional params are pretty much the same

    Pass in our params and give them default values

    Use the class we created and create a building
    Need to ensure we have the right order for the params
    Hell if I’m going to remember that

    Using named params

    Using named params
    Here we use symbols, indicated by the “:”

    In Ruby we have blocks, which are like closures in javascript
    PHP 5.3 supports this

    Here we see a monkey throwing bananas by using a for loop
    As long as we have bananas to throw, the monkey throws them

    50 is an integer object, and we’re calling the downto method

    50 is an integer object, and we’re calling the downto method

    A block can take optional params, in this case the banana count, put between the goal posts
    The rest of the block is executable code

    The result
    What’s cool - every method in Ruby has the capability of being passed a block

    PHP uses data members to share data
    Visibility depends on the keywords used in the declaration

    The @species is similar to the PHP code
    No need for getter methods!

    attr_reader replaces our getter method
    attr_accessor replaces both the getter and setter
    attr_writer adds a setter method w/out the corresponding getter

    We have a mix of public, private, and protected based on the declaration

    Unless below the protected line, everything is public
    Protected methods cannot be publicly called

    Private methods in Ruby can be executed only within the context of the same object or derivative objects

    We can start with a string
    Retype on the fly
    Check that that’s happened

    We can start with a string
    Retype on the fly
    Check that that’s happened

    We can start with a string
    Retype on the fly
    Check that that’s happened

    We can start with a string
    Retype on the fly
    Check that that’s happened

    Quick overview of the Rails app structure and creating a Rails app

    README and Rakefile are files, the rest are directories

    app is where the bulk of the code lives

    All of the config files
    Supported databases: sqlite, postgres, mysql, oracle, MS SQL, more
    Environments: development, test, production
    Routes - all the REST goes here

    All migration files stored here (timestamped)
    Can roll forward or backward (and all data will be fubar)
    Schema.rb - current database schema

    Sqlite is default if you don’t pick the database you want
    Supports - MySQL, Postgres, Sqlite, MS SQL, Oracle, and many others

    Favorites, Groups & Events

    Rails for PHP Developers - Presentation Transcript

    1. Rails for the PHP Dev (You know youʼre curious...) November 7, 2009
    2. BIGLAMPCAMP
    3. blog.adsdevshop.com rdempsey atlanticdominionsolutions
    4. My Pet Peeves
    5. My Pet Peeves People that drive slow (in general)
    6. My Pet Peeves People that drive slow (in general) People that donʼt use their turn signal
    7. My Pet Peeves People that drive slow (in general) People that donʼt use their turn signal People that read books while they drive
    8. My Pet Peeves People that drive slow (in general) People that donʼt use their turn signal People that read books while they drive People that canʼt make up their mind
    9. My Pet Peeves People that drive slow (in general) People that donʼt use their turn signal People that read books while they drive People that canʼt make up their mind People that post anonymous comments (weak)
    10. My Pet Peeves People that drive slow (in general) People that donʼt use their turn signal People that read books while they drive People that canʼt make up their mind People that post anonymous comments (weak) Trolls, Internet or otherwise
    11. My Pet Peeves People that drive slow (in general) People that donʼt use their turn signal People that read books while they drive People that canʼt make up their mind People that post anonymous comments (weak) Trolls, Internet or otherwise People that fuck with my sprint
    12. My Pet Peeves People that drive slow (in general) People that donʼt use their turn signal People that read books while they drive People that canʼt make up their mind People that post anonymous comments (weak) Trolls, Internet or otherwise People that fuck with my sprint Asshole bosses who wonʼt understand their people
    13. Ruby - History
    14. Ruby - History Released in 1995 by Yukihiro “Matz” Matsumoto
    15. Ruby - History Released in 1995 by Yukihiro “Matz” Matsumoto Blends Perl, Smalltalk, Eiffel, Ada, and Lisp
    16. Ruby - History Released in 1995 by Yukihiro “Matz” Matsumoto Blends Perl, Smalltalk, Eiffel, Ada, and Lisp Natural language syntax
    17. Ruby - History Released in 1995 by Yukihiro “Matz” Matsumoto Blends Perl, Smalltalk, Eiffel, Ada, and Lisp Natural language syntax Mass acceptance in 2006
    18. Ruby - Objects
    19. Ruby - Objects Everything is an object
    20. Ruby - Objects Everything is an object Everything can be given its own properties (instance variables) and actions (methods)
    21. Ruby - Objects Everything is an object Everything can be given its own properties (instance variables) and actions (methods) All types have methods and instance variables
    22. Ruby - Objects Everything is an object Everything can be given its own properties (instance variables) and actions (methods) All types have methods and instance variables The same rules apply everywhere
    23. Ruby - Objects Everything is an object Everything can be given its own properties (instance variables) and actions (methods) All types have methods and instance variables The same rules apply everywhere Remove, redefine, and extend at will
    24. Ruby on Rails - History
    25. Ruby on Rails - History Released in 2005 by David Heinemeier Hansson
    26. Ruby on Rails - History Released in 2005 by David Heinemeier Hansson Full-stack framework for developing database-backed web apps
    27. Ruby on Rails - History Released in 2005 by David Heinemeier Hansson Full-stack framework for developing database-backed web apps MVC
    28. Ruby on Rails - History Released in 2005 by David Heinemeier Hansson Full-stack framework for developing database-backed web apps MVC Builds on the power of Ruby
    29. Ruby on Rails - History Released in 2005 by David Heinemeier Hansson Full-stack framework for developing database-backed web apps MVC Builds on the power of Ruby Convention over configuration
    30. Ruby on Rails - Common Uses Dynamic web sites Data warehousing and data mining Statistics reporting Management applications Collaborative apps Community sites E-commerce ...
    31. PHP MVC Frameworks Cake PHP SolarPHP Symfony (others)
    32. Arrays - PHP
    33. Arrays - PHP in_array($needle, $haystack);
    34. Arrays - PHP in_array($needle, $haystack); array_push($haystack, $needle);
    35. Arrays - Ruby 1 2 3 4
    36. Variable Assignment - PHP
    37. Variable Assignment - PHP $a = array();
    38. Variable Assignment - PHP $a = array(); $b = $a;
    39. Variable Assignment - PHP $a = array(); $b = $a; $a[ʻfooʼ] = ʻbarʼ;
    40. Variable Assignment - PHP $a = array(); $b = $a; $a[ʻfooʼ] = ʻbarʼ; var_export($a); => array(ʻfooʼ => ʻbarʼ)
    41. Variable Assignment - PHP $a = array(); $b = $a; $a[ʻfooʼ] = ʻbarʼ; var_export($a); => array(ʻfooʼ => ʻbarʼ) var_export($b); => array()
    42. Variable Assignment - Ruby
    43. Variable Assignment - Ruby a = {} => {}
    44. Variable Assignment - Ruby a = {} => {} b=a => {}
    45. Variable Assignment - Ruby a = {} => {} b=a => {} a[ʻfooʼ] = ʻbarʻ => “bar”
    46. Variable Assignment - Ruby a = {} => {} b=a => {} a[ʻfooʼ] = ʻbarʻ => “bar” a => {“foo” => “bar”}
    47. Variable Assignment - Ruby a = {} => {} b=a => {} a[ʻfooʼ] = ʻbarʻ => “bar” a => {“foo” => “bar”} b => {“foo” => “bar”}
    48. Variable Assignment (2) - Ruby
    49. Variable Assignment (2) - Ruby a = ʻfooʻ => “foo”
    50. Variable Assignment (2) - Ruby a = ʻfooʻ => “foo” b=a => “foo”
    51. Variable Assignment (2) - Ruby a = ʻfooʻ => “foo” b=a => “foo” a.reverse! => “oof”
    52. Variable Assignment (2) - Ruby a = ʻfooʻ => “foo” b=a => “foo” a.reverse! => “oof” b.reverse! => “foo”
    53. Variable Assignment (2) - Ruby a = ʻfooʻ => “foo” b=a => “foo” a.reverse! => “oof” b.reverse! => “foo” a.equal? b => true
    54. http://www.flickr.com/photos/floridapfe/
    55. Methods - PHP class Monkey public function toss($fruit) { // toss a piece of fruit at someone } }
    56. Methods - Ruby class Monkey def toss(fruit) # toss some fruit at someone end end
    57. Methods (2) - PHP class Monkey public function toss($fruit, $feces = true) { // toss a piece of fruit at someone } }
    58. Methods (2) - Ruby class Monkey def toss(fruit, feces = true) # toss some fruit at someone end end
    59. Passing Named Params - PHP class Building { public function __construct($height = 10, $width = 10, $depth = 10) { // check and store params } }
    60. Passing Named Params (2) - PHP $b = new Building(10,20,30);
    61. Passing Named Params (3) - PHP $b = new Building(array(ʻheightʼ => 10, ʻwidthʼ => 20, ʻdepthʼ => 50));
    62. Passing Named Params - Ruby $b = Building.new(:height => 10, :width => 20, :depth => 50)
    63. Example PHP Function for ($bananas = 50, $bananas > 0; $bananas --) { echo “The monkey has thrown $bananas bananasn”; }
    64. Example Ruby Block 50.downto(1) { | num | puts “#{num} bananas thrown” }
    65. Example Ruby Block - Hidden Goodies int.downto(limit) { |i| block } => int Iterates block, passing decreasing values from int down to and including limit.
    66. Example Ruby Block 50.downto(1) { |num| puts “#{num} bananas thrown” }
    67. Example Ruby Block - Result 50 bananas thrown 49 bananas thrown 48 bananas thrown 47 bananas thrown 46 bananas thrown ... 1 bananas thrown
    68. Attributes - PHP class Monkey { protected $species; public $name; public function __construct($species, $name) { $this -> species = $species; $this -> name = $name; } }
    69. Attributes - Ruby class Monkey def initialize(species, name) @species = species @name = name end def species @species end ... end
    70. Attributes - Ruby class Monkey attr_reader :species attr_accessor :name attr_writer :bananas_eaten def initialize(species, name) ... end
    71. Method Visibility - PHP public function ... protected function ... protected function ... private function ... public function ...
    72. Method Visibility - Ruby class SomeClass def my_public_method end protected # Everything down here is protected
    73. Method Visibility - Ruby class Monkey private def format(value) value.capitalize end
    74. Typing- Ruby
    75. Typing- Ruby foo = ʻbarʻ => “bar”
    76. Typing- Ruby foo = ʻbarʻ => “bar” foo = 42 => 42
    77. Typing- Ruby foo = ʻbarʻ => “bar” foo = 42 => 42 foo + 2 => 44
    78. Typing- Ruby foo = ʻbarʻ => “bar” foo = 42 => 42 foo + 2 => 44 foo + “2”.to_i => 44
    79. Rails Application Structure README Rakefile app config db doc lib log public script test tmp vendor
    80. Rails Application Structure - app app - controllers - helpers - models - views
    81. Rails Application Structure - config config - boot.rb - database.yml - environment.rb - environments - initializers - locales - routes.rb
    82. Rails Application Structure - db db - migrations - schema.rb
    83. Rails Application Structure - The Rest doc lib log public script test tmp vendor
    84. Start a Rails App rails -d mysql railsforphpdevs
    85. Start a Rails App rails -d postgres railsforphpdevs
    86. Start a Rails App rails -d sqlite railsforphpdevs
    87. Thanks! Questions?

    + Robert DempseyRobert Dempsey, 2 weeks ago

    custom

    233 views, 0 favs, 2 embeds more stats

    In this presentation we look at the similarities an more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 233
      • 175 on SlideShare
      • 58 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 13
    Most viewed embeds
    • 55 views on http://blog.adsdevshop.com
    • 3 views on http://www.adsdevshop.com

    more

    All embeds
    • 55 views on http://blog.adsdevshop.com
    • 3 views on http://www.adsdevshop.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories