Mais conteúdo relacionado Semelhante a Ruby on Rails 3.1: Let's bring the fun back into web programing (20) Ruby on Rails 3.1: Let's bring the fun back into web programing1. presents
Ruby on Rails 3.1
Let’s bring the fun back to web programming!
Bozhidar Batsov
Technical Lead
4. It's the question that drives
us, Neo. It's the question that
brought you here. You know
the question, just as I did.
What is the question?
5. How can I be
be one happy
(web) programmer?
11. This PHP code is so
clean and elegantly
solves the problem at
hand.
Nobody, Never
12. PHP
0 10 20 30 40 50 60 70 80 90 100
OOP
FP
Performance
Productivity
Fun
15. The Zen of Python
There should be one –
and preferably only one
– obvious way to do it.
16. Python
0 10 20 30 40 50 60 70 80 90 100
OOP
FP
Performance
Productivity
Fun
22. The goal of Ruby is to make
programmers happy. I started out
to make a programming language that
would make me happy, and as a side
effect it’s made many, many programmers
happy. Especially Web
developers.
Yukihiro “Matz” Matsumoto,
creator of Ruby
23. Ruby
0 10 20 30 40 50 60 70 80 90 100
OOP
FP
Performance
Productivity
Fun
24. PHP Python Ruby
0 10 20 30 40 50 60 70 80 90 100
OOP
FP
Performance
Productivity
Fun
29. “Rails is the most well thought-out web
development framework I’ve ever used. And
that’s in a decade of doing web applications for
a living. I’ve built my own frameworks, helped
develop the Servlet API, and have created more
than a few web servers from scratch. Nobody
has done it like this before.”
James Duncan Davidson, Creator of Tomcat
and Ant
30. “Ruby on Rails is a breakthrough in
lowering the barriers of entry to
programming. Powerful web
applications that formerly might have
taken weeks or months to develop can
be produced in a matter of days.”
Tim O'Reilly, Founder of O'Reilly
Media
31. “It is impossible not to notice Ruby on
Rails. It has had a huge effect both in
and outside the Ruby community...
Rails has become a standard to which
even well-established tools are
comparing themselves to.”
Martin Fowler, Author of
-
Refactoring, PoEAA, XP Explained
32. “Rails is the killer app
for Ruby.”
Yukihiro Matsumoto,
Creator of Ruby
36. Many view (template)
options
HTML + Erb Haml
<div id="profile"> #profile
<div class="left column"> .left.column
<div id="date"><%= print_date %></div> #date= print_date
<div id="address"><%= current_user.address %></div> #address= current_user.address
</div> .right.column
<div class="right column"> #email= current_user.email
<div id="email"><%= current_user.email %></div> #bio= current_user.bio
<div id="bio"><%= current_user.bio %></div>
</div>
</div>
37. doctype html
html
head
title Slim Core Example
meta name="keywords" content="template language"
body
h1 Markup examples
div id="content" class="example1"
p Nest by indentation
== yield
- unless items.empty?
table
- for item in items do
tr
td = item.name
td = item.price
- else
p
| No items found. Please add some
inventory.
Thank you!
div id="footer"
| Copyright © 2010 Andrew Stone
= render 'tracking_code'
javascript:
$(content).do_something();
41. ActiveRecord
class Page < ActiveRecord::Base
has_many :page_images, :dependent => :destroy
validates :title, :presence => true, :uniqueness => true
validates :content, :presence => true
validates :permalink, :presence => true, :uniqueness => true
accepts_nested_attributes_for :page_images, :allow_destroy => true
def to_param
permalink
end
end
42. XML Free
development:
adapter: postgresql
database: mycoolproject
host: localhost
username: mycoolproject
password: mycoolproject
encoding: utf8
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
47. Fo
r k
me
on
Git
Hu
b!
53. $ heroku create --stack cedar
$ git push heroku master
$ heroku open
$ heroku scale web=100 worker=50
56. CoffeeScript
# Assignment:
number = 42
opposite = true
# Conditions:
number = -42 if opposite
# Functions:
square = (x) -> x * x
# Arrays:
list = [1, 2, 3, 4, 5]
# Objects:
math =
root: Math.sqrt
square: square
cube: (x) -> x * square x
# Splats:
race = (winner, runners...) ->
print winner, runners
# Existence:
alert "I knew it!" if elvis?
# Array comprehensions:
cubes = (math.cube num for num in list)
57. JavaScript
var cubes, list, math, num, number, opposite, race, square;
var __slice = Array.prototype.slice;
number = 42;
opposite = true;
if (opposite) number = -42;
square = function(x) {
return x * x;
};
list = [1, 2, 3, 4, 5];
math = {
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
}
};
race = function() {
var runners, winner;
winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
return print(winner, runners);
};
if (typeof elvis !== "undefined" && elvis !== null) alert("I knew it!");
cubes = (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = list.length; _i < _len; _i++) {
num = list[_i];
_results.push(math.cube(num));
}
return _results;
})();
59. SASS
$blue: #3bbfce; .content-navigation {
$margin: 16px; border-color: #3bbfce;
color: #2b9eab;
.content-navigation { }
border-color: $blue;
color: .border {
darken($blue, 9%); padding: 8px;
} margin: 8px;
border-color: #3bbfce;
.border { }
padding: $margin / 2;
margin: $margin / 2;
border-color: $blue;
}
60. table.hl { table.hl {
margin: 2em 0; margin: 2em 0;
td.ln { }
text-align: right; table.hl td.ln {
} text-align: right;
} }
li { li {
font: { font-family: serif;
family: serif; font-weight: bold;
weight: bold; font-size: 1.2em;
size: 1.2em; }
}
}
61. @mixin table-base { #data {
th { float: left;
text-align: center; margin-left: 10px;
font-weight: bold; }
} #data th {
td, th {padding: 2px} text-align: center;
} font-weight: bold;
}
@mixin left($dist) { #data td, #data th {
float: left; padding: 2px;
margin-left: $dist; }
}
#data {
@include left(10px);
@include table-base;
}
62. .error { .error, .badError {
border: 1px #f00; border: 1px #f00;
background: #fdd; background: #fdd;
} }
.error.intrusion {
.error.intrusion,
font-size: 1.3em;
.badError.intrusion
font-weight: bold;
{
}
font-size: 1.3em;
.badError { font-weight: bold;
@extend .error; }
border-width: 3px;
.badError {
}
border-width: 3px;
}