SlideShare una empresa de Scribd logo
1 de 46
Descargar para leer sin conexión
Ruby Isn’t
Just About Rails

Adam Wiggins
Codemash 2009
?
?
Ruby
You can’t sell a platform
You can’t sell a platform

    ...without a killer app.
A programming
language is a platform
is
the
killer
app Ruby
for
Came for Rails,
stayed for Ruby
An explosion of Ruby
projects in the past 2
years
Let’s take a tour!
Rails is:
ORM - ActiveRecord
Web Layer - ActionPack
Templating - ERB
Test Framework - Test::Unit
ORM
  ActiveRecord
class CreatePosts < ActiveRecord::Migration
  create_table :posts do |t|
     t.string :title
     t.text :body
     t.datetime :created_at
     t.integer :post_id
    end
end

$ rake db:migrate

class Post < ActiveRecord::Base
  has_many :comments
end

Post.find(:first, :conditions =>
          [ quot;title = ?quot;, quot;First postquot; ])
ORM
  ActiveRecord
  DataMapper
  Sequel
Define schema in the code
instead of the database


http://datamapper.org
class Post
  include DataMapper::Resource

  property   :id,           Serial
  property   :title,        String
  property   :body,         Text
  property   :created_at,   DateTime

  has n, :comments
end

DataMapper.auto_upgrade!

Post.first(:title => quot;First Postquot;)
Access a database with
just hashes - or map
models

http://sequel.rubyforge.org
db = Sequel.connect('mysql://root@localhost/db')

db.create_table :posts do
  primary_key :id
  varchar :title
  text :body
  datetime :created_at
end

db[:posts].filter(:title => quot;First Postquot;).first
Web Layer
   ActionPack
ActionController::Routing::Routes.draw do |map|
   map.resource :posts
end

class PostsController < ApplicationController
   def create
      @post = Post.create! params
      redirect_to(@post)
   end

      def show
         @post = Post.find(params[:id])
      end
end
Web Layer
   ActionPack
   Merb
   Sinatra
The hacker’s framework

“No code is faster than no code”


http://merbivore.org
Merb::Router.prepare do |router|
  resource :posts
end

class Posts < Merb::Controller
  def create
    @post = Post.create params
    redirect(url(:post, @post))
  end

  def show
    @post = Post.find(params[:id])
    display @post
  end
end
use_orm :datamapper
use_test :rspec
use_template_engine :erb
Merb 2.0 == Rails 3.0
Sinatra
The classy
microframework for Ruby
“Exposed simplicity instead of
hidden complexity”

http://sinatra.rubyforge.org
require 'rubygems'
require 'sinatra'
require 'lib/posts'

post '/posts'
 post = Post.create! params
 redirect quot;/posts/#{post.id}quot;
end

get '/posts/:id' do
 @post = Post.find(params[:id])
 erb :post
end
Test Framework
Unit tests
TDD
Test-Driven Development
BDD
Behavior-Driven
Development

http://behaviour-driven.org
TATFT
Test All The Darn Time
Test Framework
   Test::Unit
class PostTest < Test::Unit::TestCase

  def test_simple_slug
    post = Post.new :title => quot;First Postquot;
    assert_equal quot;first_postquot;, post.slug
  end

  def test_complex_slug
    post = Post.new :title => quot;My Post!quot;)
    assert_equal quot;my_postquot;, post.slug
  end

end
RSpec
Behavior-Driven
Development


http://rspec.info
describe Post do

  it quot;generates a url slug from the titlequot; do
    post = Post.new :title => quot;First Postquot;
    post.slug.should == quot;first_postquot;
  end

  it quot;drops punctuation from the url slugquot; do
    post = Post.new :title => quot;My Post!quot;
    post.slug.should == quot;my_postquot;
  end

end
$ rake spec:doc
Post
- generates a url slug from the title
- drops punctuation from the url slug
Templating Engine
   ERB
<div class=quot;postquot;>
  <h1><%= @post.title %></h1>
  <div class=quot;bodyquot;>
    <%= @post.body %>
  </div>
</div>
Templating Engine
   ERB
   Haml
Haml
Markup haiku



http://haml.hamptoncatlin.com
.post
  %h1= @post.title
  .body= @post.body
Ties it all together

http://rack.rubyforge.org
The End.


http://adam.blog.heroku.com


Adam Wiggins
Codemash 2009

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018Docker for Developers - PHP Detroit 2018
Docker for Developers - PHP Detroit 2018
 
Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)Using PHP Functions! (Not those functions, Google Cloud Functions)
Using PHP Functions! (Not those functions, Google Cloud Functions)
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Capybara with Rspec
Capybara with RspecCapybara with Rspec
Capybara with Rspec
 
Modern Perl Web Development with Dancer
Modern Perl Web Development with DancerModern Perl Web Development with Dancer
Modern Perl Web Development with Dancer
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Nodeconf npm 2011
Nodeconf npm 2011Nodeconf npm 2011
Nodeconf npm 2011
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 
Rails Metal, Rack, and Sinatra
Rails Metal, Rack, and SinatraRails Metal, Rack, and Sinatra
Rails Metal, Rack, and Sinatra
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
 
SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)SDPHP - Percona Toolkit (It's Basically Magic)
SDPHP - Percona Toolkit (It's Basically Magic)
 
Ruby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequelRuby off Rails---rack, sinatra and sequel
Ruby off Rails---rack, sinatra and sequel
 
WP Weekend #2 - Corcel, aneb WordPress přes Laravel
WP Weekend #2 - Corcel, aneb WordPress přes LaravelWP Weekend #2 - Corcel, aneb WordPress přes Laravel
WP Weekend #2 - Corcel, aneb WordPress přes Laravel
 
Foreman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple componentsForeman - Process manager for applications with multiple components
Foreman - Process manager for applications with multiple components
 
Lightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClientLightweight Webservices with Sinatra and RestClient
Lightweight Webservices with Sinatra and RestClient
 
Javascript asynchronous
Javascript asynchronousJavascript asynchronous
Javascript asynchronous
 
Ruby On Rails Basics
Ruby On Rails BasicsRuby On Rails Basics
Ruby On Rails Basics
 
Writing Software not Code with Cucumber
Writing Software not Code with CucumberWriting Software not Code with Cucumber
Writing Software not Code with Cucumber
 
Capistrano Overview
Capistrano OverviewCapistrano Overview
Capistrano Overview
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
 

Similar a Ruby Isn't Just About Rails

Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
railsconf
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 

Similar a Ruby Isn't Just About Rails (20)

Adventurous Merb
Adventurous MerbAdventurous Merb
Adventurous Merb
 
Integrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby AmfIntegrating Flex And Rails With Ruby Amf
Integrating Flex And Rails With Ruby Amf
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
Demystifying Maven
Demystifying MavenDemystifying Maven
Demystifying Maven
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
Building web framework with Rack
Building web framework with RackBuilding web framework with Rack
Building web framework with Rack
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Sinatra
SinatraSinatra
Sinatra
 
Rails Engine | Modular application
Rails Engine | Modular applicationRails Engine | Modular application
Rails Engine | Modular application
 
Ruby on Rails - Introduction
Ruby on Rails - IntroductionRuby on Rails - Introduction
Ruby on Rails - Introduction
 
Complex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBoxComplex Made Simple: Sleep Better with TorqueBox
Complex Made Simple: Sleep Better with TorqueBox
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Rack
RackRack
Rack
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Extracting ruby gem
Extracting ruby gemExtracting ruby gem
Extracting ruby gem
 
Capistrano
CapistranoCapistrano
Capistrano
 
2018 RubyHACK: put git to work - increase the quality of your rails project...
2018 RubyHACK:  put git to work -  increase the quality of your rails project...2018 RubyHACK:  put git to work -  increase the quality of your rails project...
2018 RubyHACK: put git to work - increase the quality of your rails project...
 

Más de Adam Wiggins (6)

Waza keynote: Idea to Delivery
Waza keynote: Idea to DeliveryWaza keynote: Idea to Delivery
Waza keynote: Idea to Delivery
 
The Epic Pivot: Heroku's Story
The Epic Pivot: Heroku's StoryThe Epic Pivot: Heroku's Story
The Epic Pivot: Heroku's Story
 
Cloud Services
Cloud ServicesCloud Services
Cloud Services
 
Next-Generation Ruby Deployment with Heroku
Next-Generation Ruby Deployment with HerokuNext-Generation Ruby Deployment with Heroku
Next-Generation Ruby Deployment with Heroku
 
Nginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP TricksNginx: Accelerate Rails, HTTP Tricks
Nginx: Accelerate Rails, HTTP Tricks
 
rush, the Ruby shell and Unix integration library
rush, the Ruby shell and Unix integration libraryrush, the Ruby shell and Unix integration library
rush, the Ruby shell and Unix integration library
 

Último

Último (20)

HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Ruby Isn't Just About Rails