SlideShare a Scribd company logo
1 of 199
Rails 3 from A to Z

      Matt Yoho
      @mattyoho


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                @speaker =              {
                  :name                 => ‘Matt Yoho’,
                  :company              => EdgeCase,
                  :writes               => [‘Ruby on Rails’],
                  :loves                => [‘Comic Books’]
                }




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                             Goals
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




             Rails is a Domain
            Specific Language
           for web applications
             written in and on
               top of Ruby.




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                               Rails 1.0
                            December 2005


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                               Rails 2.0
                            December 2007


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                   Rails 2.3
                                  March 2009


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                               Rails 3.0
                              August 2010


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                              Rails 3.0.3
                            November 2010


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                 Agenda

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                   1) Rails Overview


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                     2) Highlight new
                         features


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            3) Example app


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                       Rails concepts


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        MVC
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                              Model
                              VC
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            MView
                             C
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                             MV
                            Controller
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                     Model              class Movie < ActiveRecord::Base

                                          has_many   :nights
                                          belongs_to :genre

                                          validates :title,
                                                    :presence   => true
                                          validates :imdb_id,
                                                    :presence   => true,
                                                    :uniqueness => true

                                          before_save :parse_posters

                                          def poster_url(size = :thumb)
                                            self.posters.find do |p|
                                              p =~ /#{size}.(jpg|png)Z/i
                                            end
                                          end
                                        end


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                     Model              class Movie < ActiveRecord::Base

                                          has_many   :nights
                                          belongs_to :genre

                                          validates :title,
                                                    :presence   => true
                                          validates :imdb_id,
                                                    :presence   => true,
                                                    :uniqueness => true

                                          before_save :parse_posters

                                          def poster_url(size = :thumb)
                                            self.posters.find do |p|
                                              p =~ /#{size}.(jpg|png)Z/i
                                            end
                                          end
                                        end


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                     Model              class Movie < ActiveRecord::Base

                                          has_many   :nights
                                          belongs_to :genre

                                          validates :title,
                                                    :presence   => true
                                          validates :imdb_id,
                                                    :presence   => true,
                                                    :uniqueness => true

                                          before_save :parse_posters

                                          def poster_url(size = :thumb)
                                            self.posters.find do |p|
                                              p =~ /#{size}.(jpg|png)Z/i
                                            end
                                          end
                                        end


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                            View         <div class=”movie”>
                                           <img
                                            src=”<%= @movie.poster_url %>”
                                            alt=”<%= @movie.title %>” />

                                           <h3><%= @movie.title %></h3>
                                           <%= link_to(“See this movie”,
                                                      movies_path(@movie))
                                            %>
                                         </div>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                                          Layouts
                            View
                                         Templates

                                          Partials


                                          Partials




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                                         Layouts
                            View




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                            View
                                         Templates




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                            View


                                         Partials


                                         Partials




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




            Controller                  class MoviesController <
                                                    ApplicationController

                                          before_filter :user_of_age?

                                         def show
                                           id     = params[:id]
                                           @movie = Movie.find(id)
                                           render ‘movies/show’
                                         end

                                         private
                                         def user_of_age?
                                           unless current_user.age >= 17
                                             redirect_to(root_path)
                                           end
                                         end

                                        end


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




            Controller                  class MoviesController <
                                                    ApplicationController

                                          before_filter :user_of_age?

                                         def show
                                           id     = params[:id]
                                           @movie = Movie.find(id)
                                           render ‘movies/show’
                                         end

                                         private
                                         def user_of_age?
                                           unless current_user.age >= 17
                                             redirect_to(root_path)
                                           end
                                         end

                                        end


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                   Helpers              module MoviesHelper

                                         def movie_name(night)
                                           if night.movie.present?
                                             night.movie_title
                                           else
                                             "DUNNO YET"
                                           end
                                         end

                                        end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                    Routes              Movies::Application.routes.draw do

                                          resources :movies do
                                            resources :votes,
                                                      :only => [:create,
                                                                :destroy]
                                          end

                                        end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                     Mailer             class Notifier <
                                                       ActionMailer::Base

                                          default :from =>
                                                "invites@movienight.com",
                                                  :subject =>
                                                "You are invited!"

                                         def invited(invitation)
                                           headers[:content_type] =
                                                             'text/html'
                                           @night   = invitation.night
                                           @invitee = invitation.invitee
                                           mail :to => invitation.email
                                         end

                                        end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        DRY
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                             Don’t Repeat
                               Yourself


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z         MATT YOHO




                                          Migrations
                      class CreateMovies < ActiveRecord::Migration
                        def self.up
                          create_table :movies do |t|
                            t.string   :title
                            t.string   :imdb_id
                            t.datetime :release
                            t.text     :posters

                                t.timestamps
                              end
                            end

                        def self.down
                          drop_table :movies
                        end
                      end

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                              Model
                              class Movie < ActiveRecord::Base

                                   validates :title,
                                             :presence   => true
                                   validates :imdb_id,
                                             :presence   => true,
                                             :uniqueness => true

                                   before_save :parse_posters

                                def poster_url(size = :thumb)
                                  self.posters.find do |p|
                                    p =~ /#{size}.(jpg|png)Z/i
                                  end
                                end
                              end

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Convention

                              Configuration

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        REST
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                  Define APIs


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Resources


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                              Identified by
                                  URIs


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z         MATT YOHO




                            http://movienight.com/movies/123




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z         MATT YOHO




                            http://movienight.com/movies/123




                                           Movie

                                          id = 123
                                              ...



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            May be nested


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




           http://movienight.com/movies/123/actors/4




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




           http://movienight.com/movies/123/actors/4



                                         Movie
                                        id = 123




                                         Actor
                                         id = 4
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                               May have
                                multiple
                            representations

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                 http://movienight.com/movies/123.json




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                 http://movienight.com/movies/123.json



                                            {"movie" : {"alt_title" : "Batman
                                                 Begins", "created_at" :
                                            "2011-01-07T15:51:50Z", "id" :33,
                                         "imdb_id" : "tt0096251", "popularity" :
                                               2.0, "posters" : ["http://
                                           images.themoviedb.org/posters/1113/
                                           poster2rz_thumb.jpg "], "release" :
                                        "2005-06-17T00:00:00Z", "title" : "Batman
                                              Begins", "tmdb_id" : "18393",
                                         "updated_at" : "2011-01-07T15:51:50Z"}}


                                                                 {JSON}

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                  http://movienight.com/movies/123.xml




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                  http://movienight.com/movies/123.xml



                                        <?xml version="1.0" encoding="UTF-8"?>
                                        <movie>
                                          <title>Batman Begins</title>
                                          <created-at type="datetime">
                                            2011-01-06T22:18:44Z
                                          </created-at>
                                          <id type="integer">13</id>
                                          <imdb-id>tt0372784</imdb-id>
                                          <release type="datetime">
                                            2005-06-17T00:00:00Z
                                          </release>
                                          <tmdb-id>272</tmdb-id>
                                        </movie>


                                                                      <xml>
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                        Rely on HTTP content
                          type negotiation



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        HTTP headers




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                 http://movienight.com/movies/123.json




                                        HTTP headers


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                                  Request header
                            Accept: application/json, text/
                                   javascript, */*;




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                               Response header
                            Content-Type: application/json;




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        CRUD
                                         via
                HTTP VERBS
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                         GET POST
                                        PUT DELETE
                                         HTTP verbs



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                  READ CREATE
                                 UPDATE DELETE
                                        CRUD operations



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                             SHOW CREATE
                            UPDATE DESTROY
                                   Rails controller actions



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                             SHOW CREATE
                            UPDATE DESTROY
                              NEW EDIT INDEX

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                       GET /movies/123 HTTP/1.1
                       Accept:text/html




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




               CRUD op


                       GET /movies/123 HTTP/1.1
                       Accept:text/html




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Resource


                       GET /movies/123 HTTP/1.1
                       Accept:text/html




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                 MoviesController#show



                       GET /movies/123 HTTP/1.1
                       Accept:text/html



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                               Strongly
                            encouraged by
                                 Rails

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                              Request ->
                            Response Cycle


Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                    Feature details


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




             Commands



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            rails new ~/app/name




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                   rails new ~/app/name -T -J




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                   rails new ~/app/name -T -J
                               -T = Skip Test::Unit



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                   rails new ~/app/name -T -J
                               -J = Skip Prototype



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            rails generate <thing>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        rails server




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        rails console




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            Dependency
                            Management

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




        can't activate cucumber (= 0.4.4, runtime)
        for [], already activated cucumber-0.6.1
        for [] (Gem::LoadError)




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        $ gem install rails -v2.3.10
                                        Successfully installed activesupport-2.3.9
                                        Successfully installed activerecord-2.3.9
                                        Successfully installed actionpack-2.3.9
                                        Successfully installed actionmailer-2.3.9
                                        Successfully installed activeresource-2.3.9
                                        Successfully installed rails-2.3.9
                                        6 gems installed




                                                                                      2.3
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        $ gem install rails -v3.0.3
                                        Successfully installed activesupport-3.0.3
                                        Successfully installed builder-2.1.2
                                        Successfully installed i18n-0.5.0
                                        Successfully installed activemodel-3.0.3
                                        Successfully installed rack-1.2.1
                                        Successfully installed rack-test-0.5.7
                                        Successfully installed rack-mount-0.6.13
                                        Successfully installed tzinfo-0.3.23
                                        Successfully installed abstract-1.0.0
                                        Successfully installed erubis-2.6.6
                                        Successfully installed actionpack-3.0.3
                                        Successfully installed arel-2.0.6
                                        Successfully installed activerecord-3.0.3
                                        Successfully installed activeresource-3.0.3
                                        Successfully installed mime-types-1.16
                                        Successfully installed polyglot-0.3.1
                                        Successfully installed treetop-1.4.9
                                        Successfully installed mail-2.2.13
                                        Successfully installed actionmailer-3.0.3
                                        Successfully installed thor-0.14.6
                                        Successfully installed railties-3.0.3
                                        Successfully installed bundler-1.0.7
                                        Successfully installed rails-3.0.3



                                                                                      3.0
                                        23 gems installed




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        $ gem install rails -v3.0.3
                                        Successfully installed activesupport-3.0.3
                                        Successfully installed builder-2.1.2
                                        Successfully installed i18n-0.5.0
                                        Successfully installed activemodel-3.0.3
                                        Successfully installed rack-1.2.1
                                        Successfully installed rack-test-0.5.7
                                        Successfully installed rack-mount-0.6.13
                                        Successfully installed tzinfo-0.3.23
                                        Successfully installed abstract-1.0.0
                                        Successfully installed erubis-2.6.6
                                        Successfully installed actionpack-3.0.3
                                        Successfully installed arel-2.0.6
                                        Successfully installed activerecord-3.0.3
                                        Successfully installed activeresource-3.0.3
                                        Successfully installed mime-types-1.16
                                        Successfully installed polyglot-0.3.1
                                        Successfully installed treetop-1.4.9
                                        Successfully installed mail-2.2.13
                                        Successfully installed actionmailer-3.0.3
                                        Successfully installed thor-0.14.6
                                        Successfully installed railties-3.0.3
                                        Successfully installed bundler-1.0.7
                                        Successfully installed rails-3.0.3



                                                                                      3.0
                                        23 gems installed




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Gemfile


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                            source 'http://rubygems.org'

                            gem    'rails',               '~>   3.0.3'
                            gem    'basic_assumption',    '~>   0.4.1'
                            gem    'devise',              '~>   1.1.5'
                            gem    'dynamic_form',        '~>   1.1.3'
                            gem    'haml',                '~>   3.0.24'
                            gem    'nokogiri',            '~>   1.4.4'
                            gem    'pg',                  '~>   0.9.0'

                            gem 'ruby-debug',   '~> 0.10.3',
                                             :platforms => :mri_18
                            gem 'ruby-debug19', '~> 0.11.6',
                                             :platforms => :mri_19

                            group        :test do
                              gem        'rspec-rails',        '~> 2.4.1'
                              gem        'factory_girl_rails', '~> 1.0.0'
                              gem        'fakeweb',            '~> 1.3.0'
                            end
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                 source 'http://rubygems.org'




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




          gem 'rails', '~> 3.0.3'



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                    Name


          gem 'rails', '~> 3.0.3'



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




          gem 'rails', '~> 3.0.3'


                                        Version
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Platforms
                                         :mri
                                         :mri_18
                                         :mri_19
                                         :mswin
                                         :jruby
Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




          gem 'ruby-debug',
                   :platforms => :mri_18




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




          gem 'ruby-debug19',
                   :platforms => :mri_19




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                   Install from Git




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 gem 'basic_assumption',
   :git => 'git://github.com/mattyoho/basic_assumption.git',
   :branch => 'experimental'




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        GitHub repo


 gem 'basic_assumption',
   :git => 'git://github.com/mattyoho/basic_assumption.git',
   :branch => 'experimental'




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 gem 'basic_assumption',
   :git => 'git://github.com/mattyoho/basic_assumption.git',
   :branch => 'experimental'




                             Git repo branch

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            bundle install




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            group       :test do
                              gem       'rspec-rails'
                              gem       'cucumber'
                              gem       'fakeweb'
                            end



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




              bundle install --without test




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




             bundle open <gem name>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




             bundle open <gem name>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                   bundle update




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                bundle package




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        http://gembundler.org/

                      http://gembundler.com/man/gemfile.5.html



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                     Models

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                   The great split




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




         ActiveRecord




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                   ActiveRecord

     ActiveModel                           ActiveRelation



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        ActiveModel




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                            ActiveModel::Validations
                            ActiveModel::Callbacks
                            ActiveModel::Errors
                            ActiveModel::Dirty



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




        validates :title,
                    :presence           => true
                    :format             => /[a-zA-Z]/




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                    ActiveModel::Lint




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                         Mongoid
                                        Datamapper




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                    ActiveRelation




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Not as speedy?




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        @tenderlove


                             Comeplete rewrite of Arel



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




            Movie.
            select(‘*’)
            where(“title ILIKE %batman%”).
            order(‘release DESC’)




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




            criteria = Movie.
            select(‘*’)
            where(“title ILIKE %batman%”).
            order(‘release DESC’)




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




            criteria = Movie.
            select(‘*’)
            where(“title ILIKE %batman%”).
            order(‘release DESC’)


            criteria.to_sql


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




          "SELECT * FROM "movies" WHERE
          (title ILIKE '%batman%') ORDER
          BY title"




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        select()
                                        where()
                                        order()
                                        joins()
                                        includes()
                                        limit()
                                        group()
                                        having()
                                        etc.


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        named_scope




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        scope




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




            scope :batman_flicks,
             where(“title ILIKE %batman%”)




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                default_scope order(“title”)




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Controllers




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                           ActionController



                                        respond_to




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                          ActionController

              class MoviesController < ApplicationController

                   def show
                     @movie = Movie.find(params[:id])
                     respond_to do |format|
                       format.json { render :json => @movie.to_json }
                       format.xml { render :json => @movie.to_xml }
                       format.html { render ‘movies/show’ }
                     end
                   end

              end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                            ActionController



                                        respond_with




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                          ActionController

              class MoviesController < ApplicationController

                   respond_to :json, :xml, :html

                   def show
                     @movie = Movie.find(params[:id])
                     respond_with(@movie, :status => :ok)
                   end

              end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        ActionMailer
    class Mailer < ActionMailer::Base

         default :from    => "invites@movienightapp.com",
                 :subject => "You’ve been invited to a movie night!"

         def invitation(invitation)
           headers[:content_type] = 'text/html'
           @night, @invitee = invitation.night, invitation.invitee
           mail :to => invitation.email
         end

    end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        ActionMailer
    class Mailer < ActionMailer::Base

         default :from    => "invites@movienightapp.com",
                 :subject => "You’ve been invited to a movie night!"

         def invitation(invitation)
           headers[:content_type] = 'text/html'
           @night, @invitee = invitation.night, invitation.invitee
           mail :to => invitation.email
         end

    end


     message = Mailer.invitation(@invitation)
     message.deliver




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        mail gem




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        ActionMailer::Base


                       AbstractController::Base

                                   ActionController::Base



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Views




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




             Whitelist, not blacklist




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 <%= h(@movie.description) %>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




   <%= @movie.description %>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




    <%= raw(“<h2>#{@movie.title}</h2>”) %>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




    <%= raw(“<h2>#{@movie.title}</h2>”) %>




              String#html_safe




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                   Unobtrusive JS




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




               link_to_remote "Destroy",
                           :url => movie_url(@movie),
                           :method => :delete




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




               link_to_remote "Destroy",
                           :url => movie_url(@movie),
                           :method => :delete

                <a href="#" onclick="new Ajax.Request('/movies/4',
                {asynchronous:true, evalScripts:true, method:'delete'});
                return false;">Destroy</a>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




               link_to "Destroy", movie_url(@movie),
                           :remote => true,
                           :method => :delete




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




               link_to "Destroy", movie_url(@movie),
                           :remote => true,
                           :method => :delete


<a href="/movies/4" data-remote=”true" data-method=”delete”>Destroy</a>




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                      https://github.com/rails/jquery-ujs




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




       Routing




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




      Pneumatic tubes,
     popular in the late
     19th and early 20th
         century for
   transporting messages,
          cash, etc.




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO



                                        Resources


                     Text




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 CoffeeShop::Application.routes.draw do

        resources :cups do
          resources :shots
        end

        resources :coffee_beans

 end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




            cup_shots GET       /cups/:cup_id/shots(.:format)            {:action=>"index", :controller=>"shots"}
                      POST      /cups/:cup_id/shots(.:format)            {:action=>"create", :controller=>"shots"}
         new_cup_shot GET       /cups/:cup_id/shots/new(.:format)        {:action=>"new", :controller=>"shots"}
        edit_cup_shot GET       /cups/:cup_id/shots/:id/edit(.:format)   {:action=>"edit", :controller=>"shots"}
             cup_shot GET       /cups/:cup_id/shots/:id(.:format)        {:action=>"show", :controller=>"shots"}
                      PUT       /cups/:cup_id/shots/:id(.:format)        {:action=>"update", :controller=>"shots"}
                      DELETE    /cups/:cup_id/shots/:id(.:format)        {:action=>"destroy", :controller=>"shots"}
                 cups GET       /cups(.:format)                          {:action=>"index", :controller=>"cups"}
                      POST      /cups(.:format)                          {:action=>"create", :controller=>"cups"}
              new_cup GET       /cups/new(.:format)                      {:action=>"new", :controller=>"cups"}
             edit_cup GET       /cups/:id/edit(.:format)                 {:action=>"edit", :controller=>"cups"}
                  cup GET       /cups/:id(.:format)                      {:action=>"show", :controller=>"cups"}
                      PUT       /cups/:id(.:format)                      {:action=>"update", :controller=>"cups"}
                      DELETE    /cups/:id(.:format)                      {:action=>"destroy", :controller=>"cups"}
         coffee_beans GET       /coffee_beans(.:format)                  {:action=>"index", :controller=>"coffee_beans"}
                      POST      /coffee_beans(.:format)                  {:action=>"create", :controller=>"coffee_beans"}
      new_coffee_bean GET       /coffee_beans/new(.:format)              {:action=>"new", :controller=>"coffee_beans"}
     edit_coffee_bean GET       /coffee_beans/:id/edit(.:format)         {:action=>"edit", :controller=>"coffee_beans"}
          coffee_bean GET       /coffee_beans/:id(.:format)              {:action=>"show", :controller=>"coffee_beans"}
                      PUT       /coffee_beans/:id(.:format)              {:action=>"update", :controller=>"coffee_beans"}
                      DELETE    /coffee_beans/:id(.:format)              {:action=>"destroy", :controller=>"coffee_beans"}




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




         cups GET                       /cups(.:format)            {:action=>"index"}
              POST                      /cups(.:format)            {:action=>"create}
      new_cup GET                       /cups/new(.:format)        {:action=>"new"}
     edit_cup GET                       /cups/:id/edit(.:format)   {:action=>"edit"}
          cup GET                       /cups/:id(.:format)        {:action=>"show"}
              PUT                       /cups/:id(.:format)        {:action=>"update"}
              DELETE                    /cups/:id(.:format)        {:action=>"destroy}




                                          :controller=>"cups"




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




         cups GET                       /cups(.:format)            {:action=>"index"}
              POST                      /cups(.:format)            {:action=>"create}
      new_cup GET                       /cups/new(.:format)        {:action=>"new"}
     edit_cup GET                       /cups/:id/edit(.:format)   {:action=>"edit"}
          cup GET                       /cups/:id(.:format)        {:action=>"show"}
              PUT                       /cups/:id(.:format)        {:action=>"update"}
              DELETE                    /cups/:id(.:format)        {:action=>"destroy}




                                          :controller=>"cups"




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




         cups GET                       /cups(.:format)            {:action=>"index"}
              POST                      /cups(.:format)            {:action=>"create}
      new_cup GET                       /cups/new(.:format)        {:action=>"new"}
     edit_cup GET                       /cups/:id/edit(.:format)   {:action=>"edit"}
          cup GET                       /cups/:id(.:format)        {:action=>"show"}
              PUT                       /cups/:id(.:format)        {:action=>"update"}
              DELETE                    /cups/:id(.:format)        {:action=>"destroy}




                                          :controller=>"cups"




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 CoffeeShop::Application.routes.draw do

        resources :cups do
          resources :shots
        end

        resources :coffee_beans, :except => :destroy

 end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 CoffeeShop::Application.routes.draw do

        resources :cups do
          resources :shots
        end

        resources :coffee_beans,
                  :only => [:new, :show]

 end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 CoffeeShop::Application.routes.draw do

        resources :cups do
          resources :shots
        end

        resources :coffee_beans,
                  :path_names => [:edit => ‘brew’]

 end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




 CoffeeShop::Application.routes.draw do

        resources :cups do
          resources :shots
        end

        resources :coffee_beans
        resource :shop, :except => [:destroy]

 end




Tuesday, February 8, 2011
RAILS3 ROUTES MATT YOHO




                            Singular
                              Routes

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




               Simple routes


         Movienight::Application.routes.draw do

                 match "/search", :to => "movies#search"

         end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                Named routes

        Movienight::Application.routes.draw do

               match "/search", :to => "movies#search",
                                :as => "title_search"

        end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                Method-constrained routes

        Movienight::Application.routes.draw do

               match "/search", :to => "movies#show",
                                :via => :get

        end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                Method-constrained routes

        Movienight::Application.routes.draw do

               get "/search", :to => "movies#search",
                                   :via => :get

        end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




           Root route


           Movienight::Application.routes.draw do

                   root :to => "nights#index"

           end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                            Non-resourceful
                            Methods

Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




               CoffeeShop::Application.routes.draw do

                      resources :coffee_beans do
                        collection do
                          get :dark_roast
                          get :light_roast
                        end

                        member do
                          put :chew
                        end
                      end

               end


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Constraints




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     Movienight::Application.routes.draw do

             match "/search", :constraints =>
                        {:subdomain => "mst3k"}

     end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     Movienight::Application.routes.draw do

             match "/movies/:imdb_id", :constraints =>
                                  {:imdb_id => /d+/}

     end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     Movienight::Application.routes.draw do

             constraints(:subdomain => "mst3k") do
               resource :projector do
                 resources :bmovies
               end
             end

     end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Optional
                                        Segments



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     # Rails 2
     ActionController::Routing::Routes.draw do |map|

            map.connect "/:controller/:action/:id"

     end
      
     # Rails 3
     Movienight::Application.routes.draw do

            match "/:controller(/:action(/:id))(.:format)"

     end



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z
   Rack                     MATT YOHO




   Endpoints




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            Rack



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     Movienight::Application.routes.draw do

            match "/hello", :to => Proc.new do |env|
              [
                200,
                {‘Content-Type’ => ‘text/plain’},
                [“Hello, world”]
              ]
            end

     end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     Movienight::Application.routes.draw do

            match "/hello", :to => Proc.new do |env|
              [
                200,
                {‘Content-Type’ => ‘text/plain’},
                [“Hello, world”]
              ]
            end

     end
hello             /hello(.:format)      {:to=>#<Proc:0x00000100f1da28@/app/config/routes.rb:7>}




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                  Sinatra




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                     require 'sinatra/base'
                       class ApiApp < Sinatra::Base

                              get "/hello" do
                                whom = request.cookies["whom"]
                                whom ||= "world"
                                set_cookie(‘whom’, whom)
                                "Hello, #{whom}"
                              end

                              post "/hello" do
                                set_cookie(‘whom’, params[:whom])
                                redirect "/hello"
                              end
                            end


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     Movienight::Application.routes.draw do
       scope "/api" do
         match "(*path)", :to => ApiApp
       end
     end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        mount




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




     Movienight::Application.routes.draw do

            mount ApiApp, :at => "/api"

     end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Special
                                         case?



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




         Movienight::Application.routes.draw do

                 match "/search", :to => "movies#search"

         end




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




       MoviesController.action(:search)



         Movienight::Application.routes.draw do

                 match "/search", :to => "movies#search"

         end



Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                        Example


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                  Movienight


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                                  Resources


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                       http://railsapi.com


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z        MATT YOHO




                            Rails for Zombies
                                  http://railsforzombies.org/




Tuesday, February 8, 2011
RAILS 3 FROM A TO Z         MATT YOHO




                                   Rails 3 Cheat
                                       Sheets
                            http://blog.envylabs.com/2010/12/
                                    rails-3-cheat-sheets/


Tuesday, February 8, 2011
RAILS 3 FROM A TO Z       MATT YOHO




                            Rails 3 Upgrade
                              Handbook
                            http://www.railsupgradehandbook.com/




Tuesday, February 8, 2011
Thank you!

      Matt Yoho
      @mattyoho
      matt@edgecase.com

Tuesday, February 8, 2011

More Related Content

Viewers also liked

Master template5
Master template5Master template5
Master template5Theogus
 
Greener Greater Building Plan Overview
Greener Greater Building Plan Overview Greener Greater Building Plan Overview
Greener Greater Building Plan Overview REBNY
 
Univesidad tecnica particular de loja
Univesidad tecnica particular de lojaUnivesidad tecnica particular de loja
Univesidad tecnica particular de lojaAndrea
 
Ricardo sarmiento visibilidad_diseminación_portafolio
Ricardo sarmiento visibilidad_diseminación_portafolioRicardo sarmiento visibilidad_diseminación_portafolio
Ricardo sarmiento visibilidad_diseminación_portafoliochisnet
 
Graduation Project The Dream Act 1
Graduation Project The Dream Act 1Graduation Project The Dream Act 1
Graduation Project The Dream Act 1mariah4everpeace
 
NYC Energy Benchmarking Checklist
NYC Energy Benchmarking ChecklistNYC Energy Benchmarking Checklist
NYC Energy Benchmarking ChecklistREBNY
 
CENTROAVTO Investor presentation 2010
CENTROAVTO Investor presentation 2010CENTROAVTO Investor presentation 2010
CENTROAVTO Investor presentation 2010CENTROCAPITAL Inc
 
CiL11 MultiGens & Tech Change
CiL11 MultiGens & Tech ChangeCiL11 MultiGens & Tech Change
CiL11 MultiGens & Tech ChangeColleen Harris
 
White paper stopping counterfeit pharmaceuticals 0309
White  paper stopping counterfeit pharmaceuticals 0309White  paper stopping counterfeit pharmaceuticals 0309
White paper stopping counterfeit pharmaceuticals 0309NEW Momentum
 

Viewers also liked (17)

Online Questionnaire
Online QuestionnaireOnline Questionnaire
Online Questionnaire
 
Master template5
Master template5Master template5
Master template5
 
Greener Greater Building Plan Overview
Greener Greater Building Plan Overview Greener Greater Building Plan Overview
Greener Greater Building Plan Overview
 
Cute
CuteCute
Cute
 
Univesidad tecnica particular de loja
Univesidad tecnica particular de lojaUnivesidad tecnica particular de loja
Univesidad tecnica particular de loja
 
How To Kill A Community
How To Kill A CommunityHow To Kill A Community
How To Kill A Community
 
HP Fossology v5.3
HP Fossology v5.3HP Fossology v5.3
HP Fossology v5.3
 
Ricardo sarmiento visibilidad_diseminación_portafolio
Ricardo sarmiento visibilidad_diseminación_portafolioRicardo sarmiento visibilidad_diseminación_portafolio
Ricardo sarmiento visibilidad_diseminación_portafolio
 
Panduan Jurnalis Meliput Mahkamah Kontitusi
Panduan Jurnalis Meliput Mahkamah KontitusiPanduan Jurnalis Meliput Mahkamah Kontitusi
Panduan Jurnalis Meliput Mahkamah Kontitusi
 
Graduation Project The Dream Act 1
Graduation Project The Dream Act 1Graduation Project The Dream Act 1
Graduation Project The Dream Act 1
 
NYC Energy Benchmarking Checklist
NYC Energy Benchmarking ChecklistNYC Energy Benchmarking Checklist
NYC Energy Benchmarking Checklist
 
CENTROAVTO Investor presentation 2010
CENTROAVTO Investor presentation 2010CENTROAVTO Investor presentation 2010
CENTROAVTO Investor presentation 2010
 
Oss for undergraduate - fossa2010
Oss for undergraduate - fossa2010Oss for undergraduate - fossa2010
Oss for undergraduate - fossa2010
 
Bug tracking - fossa2010
Bug tracking - fossa2010Bug tracking - fossa2010
Bug tracking - fossa2010
 
Reportase jurnalisme lingkungan
Reportase jurnalisme lingkunganReportase jurnalisme lingkungan
Reportase jurnalisme lingkungan
 
CiL11 MultiGens & Tech Change
CiL11 MultiGens & Tech ChangeCiL11 MultiGens & Tech Change
CiL11 MultiGens & Tech Change
 
White paper stopping counterfeit pharmaceuticals 0309
White  paper stopping counterfeit pharmaceuticals 0309White  paper stopping counterfeit pharmaceuticals 0309
White paper stopping counterfeit pharmaceuticals 0309
 

Recently uploaded

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)wesley chun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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 RobisonAnna Loughnan Colquhoun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
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...Enterprise Knowledge
 
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 productivityPrincipled Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
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 WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
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.pptxHampshireHUG
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Recently uploaded (20)

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)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
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...
 
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
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Rails 3 from A to Z

  • 1. Rails 3 from A to Z Matt Yoho @mattyoho Tuesday, February 8, 2011
  • 2. RAILS 3 FROM A TO Z MATT YOHO @speaker = { :name => ‘Matt Yoho’, :company => EdgeCase, :writes => [‘Ruby on Rails’], :loves => [‘Comic Books’] } Tuesday, February 8, 2011
  • 3. RAILS 3 FROM A TO Z MATT YOHO Goals Tuesday, February 8, 2011
  • 4. RAILS 3 FROM A TO Z MATT YOHO Rails is a Domain Specific Language for web applications written in and on top of Ruby. Tuesday, February 8, 2011
  • 5. RAILS 3 FROM A TO Z MATT YOHO Rails 1.0 December 2005 Tuesday, February 8, 2011
  • 6. RAILS 3 FROM A TO Z MATT YOHO Rails 2.0 December 2007 Tuesday, February 8, 2011
  • 7. RAILS 3 FROM A TO Z MATT YOHO Rails 2.3 March 2009 Tuesday, February 8, 2011
  • 8. RAILS 3 FROM A TO Z MATT YOHO Rails 3.0 August 2010 Tuesday, February 8, 2011
  • 9. RAILS 3 FROM A TO Z MATT YOHO Rails 3.0.3 November 2010 Tuesday, February 8, 2011
  • 10. RAILS 3 FROM A TO Z MATT YOHO Agenda Tuesday, February 8, 2011
  • 11. RAILS 3 FROM A TO Z MATT YOHO 1) Rails Overview Tuesday, February 8, 2011
  • 12. RAILS 3 FROM A TO Z MATT YOHO 2) Highlight new features Tuesday, February 8, 2011
  • 13. RAILS 3 FROM A TO Z MATT YOHO 3) Example app Tuesday, February 8, 2011
  • 14. RAILS 3 FROM A TO Z MATT YOHO Rails concepts Tuesday, February 8, 2011
  • 15. RAILS 3 FROM A TO Z MATT YOHO MVC Tuesday, February 8, 2011
  • 16. RAILS 3 FROM A TO Z MATT YOHO Model VC Tuesday, February 8, 2011
  • 17. RAILS 3 FROM A TO Z MATT YOHO MView C Tuesday, February 8, 2011
  • 18. RAILS 3 FROM A TO Z MATT YOHO MV Controller Tuesday, February 8, 2011
  • 19. RAILS 3 FROM A TO Z MATT YOHO Model class Movie < ActiveRecord::Base has_many :nights belongs_to :genre validates :title, :presence => true validates :imdb_id, :presence => true, :uniqueness => true before_save :parse_posters def poster_url(size = :thumb) self.posters.find do |p| p =~ /#{size}.(jpg|png)Z/i end end end Tuesday, February 8, 2011
  • 20. RAILS 3 FROM A TO Z MATT YOHO Model class Movie < ActiveRecord::Base has_many :nights belongs_to :genre validates :title, :presence => true validates :imdb_id, :presence => true, :uniqueness => true before_save :parse_posters def poster_url(size = :thumb) self.posters.find do |p| p =~ /#{size}.(jpg|png)Z/i end end end Tuesday, February 8, 2011
  • 21. RAILS 3 FROM A TO Z MATT YOHO Model class Movie < ActiveRecord::Base has_many :nights belongs_to :genre validates :title, :presence => true validates :imdb_id, :presence => true, :uniqueness => true before_save :parse_posters def poster_url(size = :thumb) self.posters.find do |p| p =~ /#{size}.(jpg|png)Z/i end end end Tuesday, February 8, 2011
  • 22. RAILS 3 FROM A TO Z MATT YOHO View <div class=”movie”> <img src=”<%= @movie.poster_url %>” alt=”<%= @movie.title %>” /> <h3><%= @movie.title %></h3> <%= link_to(“See this movie”, movies_path(@movie)) %> </div> Tuesday, February 8, 2011
  • 23. RAILS 3 FROM A TO Z MATT YOHO Layouts View Templates Partials Partials Tuesday, February 8, 2011
  • 24. RAILS 3 FROM A TO Z MATT YOHO Layouts View Tuesday, February 8, 2011
  • 25. RAILS 3 FROM A TO Z MATT YOHO View Templates Tuesday, February 8, 2011
  • 26. RAILS 3 FROM A TO Z MATT YOHO View Partials Partials Tuesday, February 8, 2011
  • 27. RAILS 3 FROM A TO Z MATT YOHO Controller class MoviesController < ApplicationController before_filter :user_of_age? def show id = params[:id] @movie = Movie.find(id) render ‘movies/show’ end private def user_of_age? unless current_user.age >= 17 redirect_to(root_path) end end end Tuesday, February 8, 2011
  • 28. RAILS 3 FROM A TO Z MATT YOHO Controller class MoviesController < ApplicationController before_filter :user_of_age? def show id = params[:id] @movie = Movie.find(id) render ‘movies/show’ end private def user_of_age? unless current_user.age >= 17 redirect_to(root_path) end end end Tuesday, February 8, 2011
  • 29. RAILS 3 FROM A TO Z MATT YOHO Helpers module MoviesHelper def movie_name(night) if night.movie.present? night.movie_title else "DUNNO YET" end end end Tuesday, February 8, 2011
  • 30. RAILS 3 FROM A TO Z MATT YOHO Routes Movies::Application.routes.draw do resources :movies do resources :votes, :only => [:create, :destroy] end end Tuesday, February 8, 2011
  • 31. RAILS 3 FROM A TO Z MATT YOHO Mailer class Notifier < ActionMailer::Base default :from => "invites@movienight.com", :subject => "You are invited!" def invited(invitation) headers[:content_type] = 'text/html' @night = invitation.night @invitee = invitation.invitee mail :to => invitation.email end end Tuesday, February 8, 2011
  • 32. RAILS 3 FROM A TO Z MATT YOHO DRY Tuesday, February 8, 2011
  • 33. RAILS 3 FROM A TO Z MATT YOHO Don’t Repeat Yourself Tuesday, February 8, 2011
  • 34. RAILS 3 FROM A TO Z MATT YOHO Migrations class CreateMovies < ActiveRecord::Migration def self.up create_table :movies do |t| t.string :title t.string :imdb_id t.datetime :release t.text :posters t.timestamps end end def self.down drop_table :movies end end Tuesday, February 8, 2011
  • 35. RAILS 3 FROM A TO Z MATT YOHO Model class Movie < ActiveRecord::Base validates :title, :presence => true validates :imdb_id, :presence => true, :uniqueness => true before_save :parse_posters def poster_url(size = :thumb) self.posters.find do |p| p =~ /#{size}.(jpg|png)Z/i end end end Tuesday, February 8, 2011
  • 36. RAILS 3 FROM A TO Z MATT YOHO Convention Configuration Tuesday, February 8, 2011
  • 37. RAILS 3 FROM A TO Z MATT YOHO REST Tuesday, February 8, 2011
  • 38. RAILS 3 FROM A TO Z MATT YOHO Define APIs Tuesday, February 8, 2011
  • 39. RAILS 3 FROM A TO Z MATT YOHO Resources Tuesday, February 8, 2011
  • 40. RAILS 3 FROM A TO Z MATT YOHO Identified by URIs Tuesday, February 8, 2011
  • 41. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123 Tuesday, February 8, 2011
  • 42. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123 Movie id = 123 ... Tuesday, February 8, 2011
  • 43. RAILS 3 FROM A TO Z MATT YOHO May be nested Tuesday, February 8, 2011
  • 44. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123/actors/4 Tuesday, February 8, 2011
  • 45. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123/actors/4 Movie id = 123 Actor id = 4 Tuesday, February 8, 2011
  • 46. RAILS 3 FROM A TO Z MATT YOHO May have multiple representations Tuesday, February 8, 2011
  • 47. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123.json Tuesday, February 8, 2011
  • 48. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123.json {"movie" : {"alt_title" : "Batman Begins", "created_at" : "2011-01-07T15:51:50Z", "id" :33, "imdb_id" : "tt0096251", "popularity" : 2.0, "posters" : ["http:// images.themoviedb.org/posters/1113/ poster2rz_thumb.jpg "], "release" : "2005-06-17T00:00:00Z", "title" : "Batman Begins", "tmdb_id" : "18393", "updated_at" : "2011-01-07T15:51:50Z"}} {JSON} Tuesday, February 8, 2011
  • 49. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123.xml Tuesday, February 8, 2011
  • 50. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123.xml <?xml version="1.0" encoding="UTF-8"?> <movie> <title>Batman Begins</title> <created-at type="datetime"> 2011-01-06T22:18:44Z </created-at> <id type="integer">13</id> <imdb-id>tt0372784</imdb-id> <release type="datetime"> 2005-06-17T00:00:00Z </release> <tmdb-id>272</tmdb-id> </movie> <xml> Tuesday, February 8, 2011
  • 51. RAILS 3 FROM A TO Z MATT YOHO Rely on HTTP content type negotiation Tuesday, February 8, 2011
  • 52. RAILS 3 FROM A TO Z MATT YOHO HTTP headers Tuesday, February 8, 2011
  • 53. RAILS 3 FROM A TO Z MATT YOHO http://movienight.com/movies/123.json HTTP headers Tuesday, February 8, 2011
  • 54. RAILS 3 FROM A TO Z MATT YOHO Request header Accept: application/json, text/ javascript, */*; Tuesday, February 8, 2011
  • 55. RAILS 3 FROM A TO Z MATT YOHO Response header Content-Type: application/json; Tuesday, February 8, 2011
  • 56. RAILS 3 FROM A TO Z MATT YOHO CRUD via HTTP VERBS Tuesday, February 8, 2011
  • 57. RAILS 3 FROM A TO Z MATT YOHO GET POST PUT DELETE HTTP verbs Tuesday, February 8, 2011
  • 58. RAILS 3 FROM A TO Z MATT YOHO READ CREATE UPDATE DELETE CRUD operations Tuesday, February 8, 2011
  • 59. RAILS 3 FROM A TO Z MATT YOHO SHOW CREATE UPDATE DESTROY Rails controller actions Tuesday, February 8, 2011
  • 60. RAILS 3 FROM A TO Z MATT YOHO SHOW CREATE UPDATE DESTROY NEW EDIT INDEX Tuesday, February 8, 2011
  • 61. RAILS 3 FROM A TO Z MATT YOHO GET /movies/123 HTTP/1.1 Accept:text/html Tuesday, February 8, 2011
  • 62. RAILS 3 FROM A TO Z MATT YOHO CRUD op GET /movies/123 HTTP/1.1 Accept:text/html Tuesday, February 8, 2011
  • 63. RAILS 3 FROM A TO Z MATT YOHO Resource GET /movies/123 HTTP/1.1 Accept:text/html Tuesday, February 8, 2011
  • 64. RAILS 3 FROM A TO Z MATT YOHO MoviesController#show GET /movies/123 HTTP/1.1 Accept:text/html Tuesday, February 8, 2011
  • 65. RAILS 3 FROM A TO Z MATT YOHO Strongly encouraged by Rails Tuesday, February 8, 2011
  • 66. RAILS 3 FROM A TO Z MATT YOHO Request -> Response Cycle Tuesday, February 8, 2011
  • 76. RAILS 3 FROM A TO Z MATT YOHO Feature details Tuesday, February 8, 2011
  • 77. RAILS 3 FROM A TO Z MATT YOHO Tuesday, February 8, 2011
  • 78. RAILS 3 FROM A TO Z MATT YOHO Commands Tuesday, February 8, 2011
  • 79. RAILS 3 FROM A TO Z MATT YOHO rails new ~/app/name Tuesday, February 8, 2011
  • 80. RAILS 3 FROM A TO Z MATT YOHO rails new ~/app/name -T -J Tuesday, February 8, 2011
  • 81. RAILS 3 FROM A TO Z MATT YOHO rails new ~/app/name -T -J -T = Skip Test::Unit Tuesday, February 8, 2011
  • 82. RAILS 3 FROM A TO Z MATT YOHO rails new ~/app/name -T -J -J = Skip Prototype Tuesday, February 8, 2011
  • 83. RAILS 3 FROM A TO Z MATT YOHO rails generate <thing> Tuesday, February 8, 2011
  • 84. RAILS 3 FROM A TO Z MATT YOHO rails server Tuesday, February 8, 2011
  • 85. RAILS 3 FROM A TO Z MATT YOHO rails console Tuesday, February 8, 2011
  • 86. RAILS 3 FROM A TO Z MATT YOHO Dependency Management Tuesday, February 8, 2011
  • 87. RAILS 3 FROM A TO Z MATT YOHO can't activate cucumber (= 0.4.4, runtime) for [], already activated cucumber-0.6.1 for [] (Gem::LoadError) Tuesday, February 8, 2011
  • 88. RAILS 3 FROM A TO Z MATT YOHO $ gem install rails -v2.3.10 Successfully installed activesupport-2.3.9 Successfully installed activerecord-2.3.9 Successfully installed actionpack-2.3.9 Successfully installed actionmailer-2.3.9 Successfully installed activeresource-2.3.9 Successfully installed rails-2.3.9 6 gems installed 2.3 Tuesday, February 8, 2011
  • 89. RAILS 3 FROM A TO Z MATT YOHO $ gem install rails -v3.0.3 Successfully installed activesupport-3.0.3 Successfully installed builder-2.1.2 Successfully installed i18n-0.5.0 Successfully installed activemodel-3.0.3 Successfully installed rack-1.2.1 Successfully installed rack-test-0.5.7 Successfully installed rack-mount-0.6.13 Successfully installed tzinfo-0.3.23 Successfully installed abstract-1.0.0 Successfully installed erubis-2.6.6 Successfully installed actionpack-3.0.3 Successfully installed arel-2.0.6 Successfully installed activerecord-3.0.3 Successfully installed activeresource-3.0.3 Successfully installed mime-types-1.16 Successfully installed polyglot-0.3.1 Successfully installed treetop-1.4.9 Successfully installed mail-2.2.13 Successfully installed actionmailer-3.0.3 Successfully installed thor-0.14.6 Successfully installed railties-3.0.3 Successfully installed bundler-1.0.7 Successfully installed rails-3.0.3 3.0 23 gems installed Tuesday, February 8, 2011
  • 90. RAILS 3 FROM A TO Z MATT YOHO $ gem install rails -v3.0.3 Successfully installed activesupport-3.0.3 Successfully installed builder-2.1.2 Successfully installed i18n-0.5.0 Successfully installed activemodel-3.0.3 Successfully installed rack-1.2.1 Successfully installed rack-test-0.5.7 Successfully installed rack-mount-0.6.13 Successfully installed tzinfo-0.3.23 Successfully installed abstract-1.0.0 Successfully installed erubis-2.6.6 Successfully installed actionpack-3.0.3 Successfully installed arel-2.0.6 Successfully installed activerecord-3.0.3 Successfully installed activeresource-3.0.3 Successfully installed mime-types-1.16 Successfully installed polyglot-0.3.1 Successfully installed treetop-1.4.9 Successfully installed mail-2.2.13 Successfully installed actionmailer-3.0.3 Successfully installed thor-0.14.6 Successfully installed railties-3.0.3 Successfully installed bundler-1.0.7 Successfully installed rails-3.0.3 3.0 23 gems installed Tuesday, February 8, 2011
  • 91. RAILS 3 FROM A TO Z MATT YOHO Gemfile Tuesday, February 8, 2011
  • 92. RAILS 3 FROM A TO Z MATT YOHO source 'http://rubygems.org' gem 'rails', '~> 3.0.3' gem 'basic_assumption', '~> 0.4.1' gem 'devise', '~> 1.1.5' gem 'dynamic_form', '~> 1.1.3' gem 'haml', '~> 3.0.24' gem 'nokogiri', '~> 1.4.4' gem 'pg', '~> 0.9.0' gem 'ruby-debug', '~> 0.10.3', :platforms => :mri_18 gem 'ruby-debug19', '~> 0.11.6', :platforms => :mri_19 group :test do gem 'rspec-rails', '~> 2.4.1' gem 'factory_girl_rails', '~> 1.0.0' gem 'fakeweb', '~> 1.3.0' end Tuesday, February 8, 2011
  • 93. RAILS 3 FROM A TO Z MATT YOHO source 'http://rubygems.org' Tuesday, February 8, 2011
  • 94. RAILS 3 FROM A TO Z MATT YOHO gem 'rails', '~> 3.0.3' Tuesday, February 8, 2011
  • 95. RAILS 3 FROM A TO Z MATT YOHO Name gem 'rails', '~> 3.0.3' Tuesday, February 8, 2011
  • 96. RAILS 3 FROM A TO Z MATT YOHO gem 'rails', '~> 3.0.3' Version Tuesday, February 8, 2011
  • 97. RAILS 3 FROM A TO Z MATT YOHO Platforms :mri :mri_18 :mri_19 :mswin :jruby Tuesday, February 8, 2011
  • 98. RAILS 3 FROM A TO Z MATT YOHO gem 'ruby-debug', :platforms => :mri_18 Tuesday, February 8, 2011
  • 99. RAILS 3 FROM A TO Z MATT YOHO gem 'ruby-debug19', :platforms => :mri_19 Tuesday, February 8, 2011
  • 100. RAILS 3 FROM A TO Z MATT YOHO Install from Git Tuesday, February 8, 2011
  • 101. RAILS 3 FROM A TO Z MATT YOHO gem 'basic_assumption', :git => 'git://github.com/mattyoho/basic_assumption.git', :branch => 'experimental' Tuesday, February 8, 2011
  • 102. RAILS 3 FROM A TO Z MATT YOHO GitHub repo gem 'basic_assumption', :git => 'git://github.com/mattyoho/basic_assumption.git', :branch => 'experimental' Tuesday, February 8, 2011
  • 103. RAILS 3 FROM A TO Z MATT YOHO gem 'basic_assumption', :git => 'git://github.com/mattyoho/basic_assumption.git', :branch => 'experimental' Git repo branch Tuesday, February 8, 2011
  • 104. RAILS 3 FROM A TO Z MATT YOHO bundle install Tuesday, February 8, 2011
  • 105. RAILS 3 FROM A TO Z MATT YOHO group :test do gem 'rspec-rails' gem 'cucumber' gem 'fakeweb' end Tuesday, February 8, 2011
  • 106. RAILS 3 FROM A TO Z MATT YOHO bundle install --without test Tuesday, February 8, 2011
  • 107. RAILS 3 FROM A TO Z MATT YOHO bundle open <gem name> Tuesday, February 8, 2011
  • 108. RAILS 3 FROM A TO Z MATT YOHO bundle open <gem name> Tuesday, February 8, 2011
  • 109. RAILS 3 FROM A TO Z MATT YOHO bundle update Tuesday, February 8, 2011
  • 110. RAILS 3 FROM A TO Z MATT YOHO bundle package Tuesday, February 8, 2011
  • 111. RAILS 3 FROM A TO Z MATT YOHO http://gembundler.org/ http://gembundler.com/man/gemfile.5.html Tuesday, February 8, 2011
  • 112. RAILS 3 FROM A TO Z MATT YOHO Models Tuesday, February 8, 2011
  • 113. RAILS 3 FROM A TO Z MATT YOHO The great split Tuesday, February 8, 2011
  • 114. RAILS 3 FROM A TO Z MATT YOHO ActiveRecord Tuesday, February 8, 2011
  • 115. RAILS 3 FROM A TO Z MATT YOHO ActiveRecord ActiveModel ActiveRelation Tuesday, February 8, 2011
  • 116. RAILS 3 FROM A TO Z MATT YOHO ActiveModel Tuesday, February 8, 2011
  • 117. RAILS 3 FROM A TO Z MATT YOHO ActiveModel::Validations ActiveModel::Callbacks ActiveModel::Errors ActiveModel::Dirty Tuesday, February 8, 2011
  • 118. RAILS 3 FROM A TO Z MATT YOHO validates :title, :presence => true :format => /[a-zA-Z]/ Tuesday, February 8, 2011
  • 119. RAILS 3 FROM A TO Z MATT YOHO ActiveModel::Lint Tuesday, February 8, 2011
  • 120. RAILS 3 FROM A TO Z MATT YOHO Mongoid Datamapper Tuesday, February 8, 2011
  • 121. RAILS 3 FROM A TO Z MATT YOHO ActiveRelation Tuesday, February 8, 2011
  • 122. RAILS 3 FROM A TO Z MATT YOHO Not as speedy? Tuesday, February 8, 2011
  • 123. RAILS 3 FROM A TO Z MATT YOHO @tenderlove Comeplete rewrite of Arel Tuesday, February 8, 2011
  • 124. RAILS 3 FROM A TO Z MATT YOHO Movie. select(‘*’) where(“title ILIKE %batman%”). order(‘release DESC’) Tuesday, February 8, 2011
  • 125. RAILS 3 FROM A TO Z MATT YOHO criteria = Movie. select(‘*’) where(“title ILIKE %batman%”). order(‘release DESC’) Tuesday, February 8, 2011
  • 126. RAILS 3 FROM A TO Z MATT YOHO criteria = Movie. select(‘*’) where(“title ILIKE %batman%”). order(‘release DESC’) criteria.to_sql Tuesday, February 8, 2011
  • 127. RAILS 3 FROM A TO Z MATT YOHO "SELECT * FROM "movies" WHERE (title ILIKE '%batman%') ORDER BY title" Tuesday, February 8, 2011
  • 128. RAILS 3 FROM A TO Z MATT YOHO select() where() order() joins() includes() limit() group() having() etc. Tuesday, February 8, 2011
  • 129. RAILS 3 FROM A TO Z MATT YOHO named_scope Tuesday, February 8, 2011
  • 130. RAILS 3 FROM A TO Z MATT YOHO scope Tuesday, February 8, 2011
  • 131. RAILS 3 FROM A TO Z MATT YOHO scope :batman_flicks, where(“title ILIKE %batman%”) Tuesday, February 8, 2011
  • 132. RAILS 3 FROM A TO Z MATT YOHO default_scope order(“title”) Tuesday, February 8, 2011
  • 133. RAILS 3 FROM A TO Z MATT YOHO Controllers Tuesday, February 8, 2011
  • 134. RAILS 3 FROM A TO Z MATT YOHO ActionController respond_to Tuesday, February 8, 2011
  • 135. RAILS 3 FROM A TO Z MATT YOHO ActionController class MoviesController < ApplicationController def show @movie = Movie.find(params[:id]) respond_to do |format| format.json { render :json => @movie.to_json } format.xml { render :json => @movie.to_xml } format.html { render ‘movies/show’ } end end end Tuesday, February 8, 2011
  • 136. RAILS 3 FROM A TO Z MATT YOHO ActionController respond_with Tuesday, February 8, 2011
  • 137. RAILS 3 FROM A TO Z MATT YOHO ActionController class MoviesController < ApplicationController respond_to :json, :xml, :html def show @movie = Movie.find(params[:id]) respond_with(@movie, :status => :ok) end end Tuesday, February 8, 2011
  • 138. RAILS 3 FROM A TO Z MATT YOHO ActionMailer class Mailer < ActionMailer::Base default :from => "invites@movienightapp.com", :subject => "You’ve been invited to a movie night!" def invitation(invitation) headers[:content_type] = 'text/html' @night, @invitee = invitation.night, invitation.invitee mail :to => invitation.email end end Tuesday, February 8, 2011
  • 139. RAILS 3 FROM A TO Z MATT YOHO ActionMailer class Mailer < ActionMailer::Base default :from => "invites@movienightapp.com", :subject => "You’ve been invited to a movie night!" def invitation(invitation) headers[:content_type] = 'text/html' @night, @invitee = invitation.night, invitation.invitee mail :to => invitation.email end end message = Mailer.invitation(@invitation) message.deliver Tuesday, February 8, 2011
  • 140. RAILS 3 FROM A TO Z MATT YOHO mail gem Tuesday, February 8, 2011
  • 141. RAILS 3 FROM A TO Z MATT YOHO ActionMailer::Base AbstractController::Base ActionController::Base Tuesday, February 8, 2011
  • 142. RAILS 3 FROM A TO Z MATT YOHO Views Tuesday, February 8, 2011
  • 143. RAILS 3 FROM A TO Z MATT YOHO Whitelist, not blacklist Tuesday, February 8, 2011
  • 144. RAILS 3 FROM A TO Z MATT YOHO <%= h(@movie.description) %> Tuesday, February 8, 2011
  • 145. RAILS 3 FROM A TO Z MATT YOHO <%= @movie.description %> Tuesday, February 8, 2011
  • 146. RAILS 3 FROM A TO Z MATT YOHO <%= raw(“<h2>#{@movie.title}</h2>”) %> Tuesday, February 8, 2011
  • 147. RAILS 3 FROM A TO Z MATT YOHO <%= raw(“<h2>#{@movie.title}</h2>”) %> String#html_safe Tuesday, February 8, 2011
  • 148. RAILS 3 FROM A TO Z MATT YOHO Unobtrusive JS Tuesday, February 8, 2011
  • 149. RAILS 3 FROM A TO Z MATT YOHO link_to_remote "Destroy", :url => movie_url(@movie), :method => :delete Tuesday, February 8, 2011
  • 150. RAILS 3 FROM A TO Z MATT YOHO link_to_remote "Destroy", :url => movie_url(@movie), :method => :delete <a href="#" onclick="new Ajax.Request('/movies/4', {asynchronous:true, evalScripts:true, method:'delete'}); return false;">Destroy</a> Tuesday, February 8, 2011
  • 151. RAILS 3 FROM A TO Z MATT YOHO link_to "Destroy", movie_url(@movie), :remote => true, :method => :delete Tuesday, February 8, 2011
  • 152. RAILS 3 FROM A TO Z MATT YOHO link_to "Destroy", movie_url(@movie), :remote => true, :method => :delete <a href="/movies/4" data-remote=”true" data-method=”delete”>Destroy</a> Tuesday, February 8, 2011
  • 153. RAILS 3 FROM A TO Z MATT YOHO https://github.com/rails/jquery-ujs Tuesday, February 8, 2011
  • 154. RAILS 3 FROM A TO Z MATT YOHO Routing Tuesday, February 8, 2011
  • 155. RAILS 3 FROM A TO Z MATT YOHO Pneumatic tubes, popular in the late 19th and early 20th century for transporting messages, cash, etc. Tuesday, February 8, 2011
  • 156. RAILS 3 FROM A TO Z MATT YOHO Resources Text Tuesday, February 8, 2011
  • 157. RAILS 3 FROM A TO Z MATT YOHO CoffeeShop::Application.routes.draw do resources :cups do resources :shots end resources :coffee_beans end Tuesday, February 8, 2011
  • 158. RAILS 3 FROM A TO Z MATT YOHO cup_shots GET /cups/:cup_id/shots(.:format) {:action=>"index", :controller=>"shots"} POST /cups/:cup_id/shots(.:format) {:action=>"create", :controller=>"shots"} new_cup_shot GET /cups/:cup_id/shots/new(.:format) {:action=>"new", :controller=>"shots"} edit_cup_shot GET /cups/:cup_id/shots/:id/edit(.:format) {:action=>"edit", :controller=>"shots"} cup_shot GET /cups/:cup_id/shots/:id(.:format) {:action=>"show", :controller=>"shots"} PUT /cups/:cup_id/shots/:id(.:format) {:action=>"update", :controller=>"shots"} DELETE /cups/:cup_id/shots/:id(.:format) {:action=>"destroy", :controller=>"shots"} cups GET /cups(.:format) {:action=>"index", :controller=>"cups"} POST /cups(.:format) {:action=>"create", :controller=>"cups"} new_cup GET /cups/new(.:format) {:action=>"new", :controller=>"cups"} edit_cup GET /cups/:id/edit(.:format) {:action=>"edit", :controller=>"cups"} cup GET /cups/:id(.:format) {:action=>"show", :controller=>"cups"} PUT /cups/:id(.:format) {:action=>"update", :controller=>"cups"} DELETE /cups/:id(.:format) {:action=>"destroy", :controller=>"cups"} coffee_beans GET /coffee_beans(.:format) {:action=>"index", :controller=>"coffee_beans"} POST /coffee_beans(.:format) {:action=>"create", :controller=>"coffee_beans"} new_coffee_bean GET /coffee_beans/new(.:format) {:action=>"new", :controller=>"coffee_beans"} edit_coffee_bean GET /coffee_beans/:id/edit(.:format) {:action=>"edit", :controller=>"coffee_beans"} coffee_bean GET /coffee_beans/:id(.:format) {:action=>"show", :controller=>"coffee_beans"} PUT /coffee_beans/:id(.:format) {:action=>"update", :controller=>"coffee_beans"} DELETE /coffee_beans/:id(.:format) {:action=>"destroy", :controller=>"coffee_beans"} Tuesday, February 8, 2011
  • 159. RAILS 3 FROM A TO Z MATT YOHO cups GET /cups(.:format) {:action=>"index"} POST /cups(.:format) {:action=>"create} new_cup GET /cups/new(.:format) {:action=>"new"} edit_cup GET /cups/:id/edit(.:format) {:action=>"edit"} cup GET /cups/:id(.:format) {:action=>"show"} PUT /cups/:id(.:format) {:action=>"update"} DELETE /cups/:id(.:format) {:action=>"destroy} :controller=>"cups" Tuesday, February 8, 2011
  • 160. RAILS 3 FROM A TO Z MATT YOHO cups GET /cups(.:format) {:action=>"index"} POST /cups(.:format) {:action=>"create} new_cup GET /cups/new(.:format) {:action=>"new"} edit_cup GET /cups/:id/edit(.:format) {:action=>"edit"} cup GET /cups/:id(.:format) {:action=>"show"} PUT /cups/:id(.:format) {:action=>"update"} DELETE /cups/:id(.:format) {:action=>"destroy} :controller=>"cups" Tuesday, February 8, 2011
  • 161. RAILS 3 FROM A TO Z MATT YOHO cups GET /cups(.:format) {:action=>"index"} POST /cups(.:format) {:action=>"create} new_cup GET /cups/new(.:format) {:action=>"new"} edit_cup GET /cups/:id/edit(.:format) {:action=>"edit"} cup GET /cups/:id(.:format) {:action=>"show"} PUT /cups/:id(.:format) {:action=>"update"} DELETE /cups/:id(.:format) {:action=>"destroy} :controller=>"cups" Tuesday, February 8, 2011
  • 162. RAILS 3 FROM A TO Z MATT YOHO CoffeeShop::Application.routes.draw do resources :cups do resources :shots end resources :coffee_beans, :except => :destroy end Tuesday, February 8, 2011
  • 163. RAILS 3 FROM A TO Z MATT YOHO CoffeeShop::Application.routes.draw do resources :cups do resources :shots end resources :coffee_beans, :only => [:new, :show] end Tuesday, February 8, 2011
  • 164. RAILS 3 FROM A TO Z MATT YOHO CoffeeShop::Application.routes.draw do resources :cups do resources :shots end resources :coffee_beans, :path_names => [:edit => ‘brew’] end Tuesday, February 8, 2011
  • 165. RAILS 3 FROM A TO Z MATT YOHO CoffeeShop::Application.routes.draw do resources :cups do resources :shots end resources :coffee_beans resource :shop, :except => [:destroy] end Tuesday, February 8, 2011
  • 166. RAILS3 ROUTES MATT YOHO Singular Routes Tuesday, February 8, 2011
  • 167. RAILS 3 FROM A TO Z MATT YOHO Simple routes Movienight::Application.routes.draw do match "/search", :to => "movies#search" end Tuesday, February 8, 2011
  • 168. RAILS 3 FROM A TO Z MATT YOHO Named routes Movienight::Application.routes.draw do match "/search", :to => "movies#search", :as => "title_search" end Tuesday, February 8, 2011
  • 169. RAILS 3 FROM A TO Z MATT YOHO Method-constrained routes Movienight::Application.routes.draw do match "/search", :to => "movies#show", :via => :get end Tuesday, February 8, 2011
  • 170. RAILS 3 FROM A TO Z MATT YOHO Method-constrained routes Movienight::Application.routes.draw do get "/search", :to => "movies#search", :via => :get end Tuesday, February 8, 2011
  • 171. RAILS 3 FROM A TO Z MATT YOHO Root route Movienight::Application.routes.draw do root :to => "nights#index" end Tuesday, February 8, 2011
  • 172. RAILS 3 FROM A TO Z MATT YOHO Non-resourceful Methods Tuesday, February 8, 2011
  • 173. RAILS 3 FROM A TO Z MATT YOHO CoffeeShop::Application.routes.draw do resources :coffee_beans do collection do get :dark_roast get :light_roast end member do put :chew end end end Tuesday, February 8, 2011
  • 174. RAILS 3 FROM A TO Z MATT YOHO Constraints Tuesday, February 8, 2011
  • 175. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do match "/search", :constraints => {:subdomain => "mst3k"} end Tuesday, February 8, 2011
  • 176. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do match "/movies/:imdb_id", :constraints => {:imdb_id => /d+/} end Tuesday, February 8, 2011
  • 177. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do constraints(:subdomain => "mst3k") do resource :projector do resources :bmovies end end end Tuesday, February 8, 2011
  • 178. RAILS 3 FROM A TO Z MATT YOHO Optional Segments Tuesday, February 8, 2011
  • 179. RAILS 3 FROM A TO Z MATT YOHO # Rails 2 ActionController::Routing::Routes.draw do |map| map.connect "/:controller/:action/:id" end   # Rails 3 Movienight::Application.routes.draw do match "/:controller(/:action(/:id))(.:format)" end Tuesday, February 8, 2011
  • 180. RAILS 3 FROM A TO Z Rack MATT YOHO Endpoints Tuesday, February 8, 2011
  • 181. RAILS 3 FROM A TO Z MATT YOHO Rack Tuesday, February 8, 2011
  • 182. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do match "/hello", :to => Proc.new do |env| [ 200, {‘Content-Type’ => ‘text/plain’}, [“Hello, world”] ] end end Tuesday, February 8, 2011
  • 183. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do match "/hello", :to => Proc.new do |env| [ 200, {‘Content-Type’ => ‘text/plain’}, [“Hello, world”] ] end end hello /hello(.:format) {:to=>#<Proc:0x00000100f1da28@/app/config/routes.rb:7>} Tuesday, February 8, 2011
  • 184. RAILS 3 FROM A TO Z MATT YOHO Sinatra Tuesday, February 8, 2011
  • 185. RAILS 3 FROM A TO Z MATT YOHO require 'sinatra/base' class ApiApp < Sinatra::Base get "/hello" do whom = request.cookies["whom"] whom ||= "world" set_cookie(‘whom’, whom) "Hello, #{whom}" end post "/hello" do set_cookie(‘whom’, params[:whom]) redirect "/hello" end end Tuesday, February 8, 2011
  • 186. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do scope "/api" do match "(*path)", :to => ApiApp end end Tuesday, February 8, 2011
  • 187. RAILS 3 FROM A TO Z MATT YOHO mount Tuesday, February 8, 2011
  • 188. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do mount ApiApp, :at => "/api" end Tuesday, February 8, 2011
  • 189. RAILS 3 FROM A TO Z MATT YOHO Special case? Tuesday, February 8, 2011
  • 190. RAILS 3 FROM A TO Z MATT YOHO Movienight::Application.routes.draw do match "/search", :to => "movies#search" end Tuesday, February 8, 2011
  • 191. RAILS 3 FROM A TO Z MATT YOHO MoviesController.action(:search) Movienight::Application.routes.draw do match "/search", :to => "movies#search" end Tuesday, February 8, 2011
  • 192. RAILS 3 FROM A TO Z MATT YOHO Example Tuesday, February 8, 2011
  • 193. RAILS 3 FROM A TO Z MATT YOHO Movienight Tuesday, February 8, 2011
  • 194. RAILS 3 FROM A TO Z MATT YOHO Resources Tuesday, February 8, 2011
  • 195. RAILS 3 FROM A TO Z MATT YOHO http://railsapi.com Tuesday, February 8, 2011
  • 196. RAILS 3 FROM A TO Z MATT YOHO Rails for Zombies http://railsforzombies.org/ Tuesday, February 8, 2011
  • 197. RAILS 3 FROM A TO Z MATT YOHO Rails 3 Cheat Sheets http://blog.envylabs.com/2010/12/ rails-3-cheat-sheets/ Tuesday, February 8, 2011
  • 198. RAILS 3 FROM A TO Z MATT YOHO Rails 3 Upgrade Handbook http://www.railsupgradehandbook.com/ Tuesday, February 8, 2011
  • 199. Thank you! Matt Yoho @mattyoho matt@edgecase.com Tuesday, February 8, 2011

Editor's Notes

  1. http://www.flickr.com/photos/tubemail/3002309450/
  2. http://www.flickr.com/photos/26666081@N03/5154902507/
  3. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  4. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  5. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  6. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  7. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  8. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  9. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  10. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  11. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  12. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  13. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  14. http://engineering.attinteractive.com/2010/10/arel-two-point-ohhhhh-yaaaaaa/
  15. http://www.flickr.com/photos/26666081@N03/5154902507/
  16. http://www.flickr.com/photos/26666081@N03/5154902507/
  17. http://www.flickr.com/photos/26666081@N03/5154902507/
  18. http://www.flickr.com/photos/26666081@N03/5154902507/
  19. http://www.flickr.com/photos/26666081@N03/5154902507/
  20. http://www.flickr.com/photos/26666081@N03/5154902507/
  21. http://www.flickr.com/photos/26666081@N03/5154902507/
  22. http://www.flickr.com/photos/26666081@N03/5154902507/
  23. http://www.flickr.com/photos/26666081@N03/5154902507/
  24. http://www.flickr.com/photos/26666081@N03/5154902507/
  25. http://yehudakatz.com/2010/02/01/safebuffers-and-rails-3-0/
  26. http://www.flickr.com/photos/26666081@N03/5154902507/
  27. http://www.flickr.com/photos/dlanod/235990854/
  28. http://www.flickr.com/photos/curiousexpeditions/2355395524/
  29. http://www.flickr.com/photos/26666081@N03/5154866369/
  30. http://www.flickr.com/photos/tubemail/3001472687/
  31. http://www.flickr.com/photos/tubemail/3001472687/
  32. http://www.flickr.com/photos/tubemail/3001472687/
  33. http://www.flickr.com/photos/tubemail/3001472687/
  34. http://www.flickr.com/photos/tubemail/3001472687/
  35. http://www.flickr.com/photos/curiousexpeditions/2354556261/
  36. http://www.flickr.com/photos/sohvimus/3228836603/
  37. http://www.flickr.com/photos/sohvimus/3228836603/
  38. http://www.flickr.com/photos/danarah/3637584542/
  39. http://www.flickr.com/photos/sohvimus/3228836603/
  40. http://www.flickr.com/photos/sohvimus/3228836603/