9. My Pet Peeves
People that drive slow (in general)
People that donʼt use their turn signal
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
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
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)
13. 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
14. 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
15. 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
22. Ruby - History
Released in 1995 by Yukihiro “Matz” Matsumoto
Blends Perl, Smalltalk, Eiffel, Ada, and Lisp
23. Ruby - History
Released in 1995 by Yukihiro “Matz” Matsumoto
Blends Perl, Smalltalk, Eiffel, Ada, and Lisp
Natural language syntax
24. Ruby - History
Released in 1995 by Yukihiro “Matz” Matsumoto
Blends Perl, Smalltalk, Eiffel, Ada, and Lisp
Natural language syntax
Mass acceptance in 2006
27. Ruby - Objects
Everything is an object
Everything can be given its own properties (instance
variables) and actions (methods)
28. 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
29. 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
30. 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
32. Ruby on Rails - History
Released in 2005 by David Heinemeier Hansson
33. Ruby on Rails - History
Released in 2005 by David Heinemeier Hansson
Full-stack framework for developing database-backed web
apps
34. Ruby on Rails - History
Released in 2005 by David Heinemeier Hansson
Full-stack framework for developing database-backed web
apps
MVC
35. 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
36. 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
37. Ruby on Rails - Common Uses
Dynamic web sites
Data warehousing and data mining
Statistics reporting
Management applications
Collaborative apps
Community sites
E-commerce
...
76. Example Ruby Block - Hidden Goodies
int.downto(limit) { |i| block } => int
Iterates block, passing decreasing values from int down to
and including limit.
79. Attributes - PHP
class Monkey {
protected $species;
public $name;
public function __construct($species, $name) {
$this -> species = $species;
$this -> name = $name;
}
}
80. Attributes - Ruby
class Monkey
def initialize(species, name)
@species = species
@name = name
end
def species
@species
end
...
end
81. Attributes - Ruby
class Monkey
attr_reader :species
attr_accessor :name
attr_writer :bananas_eaten
def initialize(species, name)
...
end
82. Method Visibility - PHP
public function ...
protected function ...
protected function ...
private function ...
public function ...
83. Method Visibility - Ruby
class SomeClass
def my_public_method
end
protected
# Everything down here is protected
84. Method Visibility - Ruby
class Monkey
private
def format(value)
value.capitalize
end
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