SlideShare a Scribd company logo
RIDING
RAILS 4
#BCNONRAILS4
PHILIP DE SMEDT
  @PHILIPDESMEDT
PHILIPDESMEDT.COM
FREELANCE
FULL-STACK
DEVELOPER
       (HIRE ME)
I WROTE A BOOK
     UPGRADE TO RAILS 4
WHO HAS
TRIED RAILS 4?

    gem install rails --version
    4.0.0.beta1 --no-ri --no-rdoc
TURBOLINKS
CLICK
LISTENS TO

   EVENTS
LISTENS TO CLICK EVENTS

      LOADS CONTENT

    WITHOUT
   RELOADING
    THE PAGE
LISTENS TO CLICK EVENTS
LOADS CONTENT WITHOUT
RELOADING THE PAGE

   REPLACES BODY+TITLE

        HTML5
     USING

     pushState
DEMO
RUSSIAN DOLL CACHING
LET’S CACHE

class Post < ActiveRecord::Base
 has_many :categories
end

class Category < ActiveRecord::Base
 belongs_to :post, touch: true
end
RAILS 3

<!-- app/views/posts/show.html.erb -->
<% cache [„v1‟, @post] do %>
 <h1><%= @post.title %> categories:</h1>
 <ul><%= render @post.categories %></ul>
<% end %>
RAILS 3
<!-- app/views/categories/_category.html.erb -->
<% cache [„v1‟, category] do %>
 <li>
   <%= category.title %>
   <%= link_to “edit”, category %>
 </li>
<% end %>
RAILS 3 CACHE KEYS


  views/v1/posts/1-
  20130228151844
RAILS 3
<!-- app/views/categories/_category.html.erb -->

<% cache [„v2  ‟, category] do %>
 <li>
  <%= category.title %>

  <%= link_to “RENAME”, category %>
 </li>
<% end %>
RAILS 3

<!-- app/views/posts/show.html.erb -->
<% cache [„v2‟, @post] do %>
 <h1><%= @post.title %> categories:</h1>
 <ul><%= render @post.categories %></ul>
<% end %>
Riding Rails 4
<!-- app/views/posts/show.html.erb -->
<% cache @post do %>
 <h1><%= @post.title %> categories:</h1>
 <ul><%= render @post.categories %></ul>
<% end %>
<!-- app/views/categories/_category.html.erb -->
<% cache category do %>
 <li>
   <%= category.title %>
   <%= link_to “edit”, category %>
 </li>
<% end %>
RAILS 4 CACHE DIGEST

views/posts/1-
20130228151844/fbda9857
614e68ed1df453559a761d4
7
STRONG PARAMETERS
RAILS 3

class User < ActiveRecord::Base
     attr_accessible :name, :email
end

def create
  @user = User.new(params[:user])
  @user.save
end
EXAMPLE
RAILS 4

class CarsController < ApplicationController
   def create
           @car = Car.new(car_params)
           if @car.save
            redirect_to @car
           else
               render „new‟
         end
    end
end
private
  def car_params
   params.require(:car).permit(:name, :year, :brand)
  end


require(key) - Ensures that a parameter is present. If it‟s present,
returns the parameter at the given key, otherwise raises an
ActionController:: ParameterMissing error.

permit(filters) - Returns a new ActionController::Parameters
instance that includes only the given filters
and sets the permitted attribute for the object to true. This is useful
for limiting which attributes should be allowed for mass updating.
LIVE STREAMING
ACTIONCONTROLLER::LIVE

MIXIN I/O OBJECT
STREAM DATA TO CLIENT
DON’T USE
WEBrick
USE PUMA OR RAINBOWS!
RUNS IN
SEPARATE
 THREAD
CLOSE YOUR
STREAM WHEN
    DONE
PUMA vs.
RAINBOWS! vs.
  NODE.JS
RUBYSNIPPETS.COM
Riding Rails 4
DEMO
ACTIVEMODEL::MODEL
FORM WITHOUT
ACTIVE RECORD.
     WTF?
FORM_TAG
  HELPER

CREATE MODEL
EXAMPLE
class Contact
   include ActiveModel::Model

  attr_accessor :name, :email, :message
  validates :name, presence: true
  validates :email, presence: true
  validates :message, presence: true, length:
  { maximum: 300 }
end

contact = Contact.new(name: 'John Doe', email:
'john@doe.com', message: 'a test')
<h1>Contact Us</h1>

<%= form_for @contact do |f| %>
  <%= f.label :name %>
  <%= f.text_field :name %>
  <%= f.label :email %>
  <%= f.email_field :email %>
  <%= f.label :message %>
  <%= f.text_area :message %>
  <%= f.submit 'Submit' %>
<% end %>
class ContactsController < ApplicationController
    def new
        @contact = Contact.new
    end

      def create
          @contact = Contact.new(params[:contact])
          if @contact.valid?
              UserMailer.new_contact(@contact).deliver
              redirect_to root_path, notice: "Message sent! Thanks.”
           else
              render :new
          end
      end
end
LOTS OF OTHER STUFF
  ROUTING CONCERNS          THREAD SAFETY


CONTROLLER-WIDE E-TAGS        ENCRYPTED COOKIES

               HTTP PATCH VERB
                                     CUSTOM FLASH TYPES
HTML5 FORM HELPERS

                                   SCHEMA CACHE DUMP
      PAGE/ACTION CACHING

           NO MORE OBSERVERS/SWEEPERS

     ACTIVE RESOURCE             INDEX PAGE CONTROLLER
EDUCATION IS BROKEN.
I’LL BE TEACHING RAILS…
            IN BARCELONA.



          I <3 DEVBOOTCAMP/STARTER LEAGUE/…
COME SAY HI

    PHILIP DE SMEDT
            @PHILIPDESMEDT

          PHILIPDESMEDT.COM

LEANPUB.COM/UPGRADETORAILS4

More Related Content

PPT
Drupal Gardens tutorial 3 of 4
PPTX
RubyConf Bangladesh 2017 - Elixir for Rubyists
PPT
How to remove search.olivernetko.com manually
PDF
How not to suck at Cyber Security
PDF
Dfyt step-three-v2
PDF
Zero To WordPress Plubish
PPT
Facebook + Ruby
PPTX
The Power of HTML5 Offline: Mobile and More!
Drupal Gardens tutorial 3 of 4
RubyConf Bangladesh 2017 - Elixir for Rubyists
How to remove search.olivernetko.com manually
How not to suck at Cyber Security
Dfyt step-three-v2
Zero To WordPress Plubish
Facebook + Ruby
The Power of HTML5 Offline: Mobile and More!

What's hot (20)

PPTX
Custom Template for Joomla! 3
ODP
Beginning WordPress Plugin Development
PPT
How to remove alhea.com from your computer
PDF
Copycat Site BluePrint - make money online fast
PDF
Scraping Handout
PDF
Joomla Quick Start 1
DOCX
2222
PDF
Using Wordpress with Reclaim Hosting
PPSX
Sweet-page.com
ODP
45 Minute Drupal Site
PDF
Really Awesome WordPress Plugins You Should Know About
ODP
Facebook Social Plugins
PDF
Riann salandanan howtouse_canva
DOC
Cbcode volume2
PDF
Material emociones
PDF
How to use a SharePoint Team Site effectively for Collaboration
PPTX
Killer KPIs: Turning Data into Gs
PDF
Jabber Bot
PPTX
2014 adp login training
PPTX
Adp login training
Custom Template for Joomla! 3
Beginning WordPress Plugin Development
How to remove alhea.com from your computer
Copycat Site BluePrint - make money online fast
Scraping Handout
Joomla Quick Start 1
2222
Using Wordpress with Reclaim Hosting
Sweet-page.com
45 Minute Drupal Site
Really Awesome WordPress Plugins You Should Know About
Facebook Social Plugins
Riann salandanan howtouse_canva
Cbcode volume2
Material emociones
How to use a SharePoint Team Site effectively for Collaboration
Killer KPIs: Turning Data into Gs
Jabber Bot
2014 adp login training
Adp login training
Ad

Similar to Riding Rails 4 (20)

PDF
Rails 4.0
ODP
Introduction to rails 4 v1
PDF
What's new in Rails 4
PDF
What's new in ruby on rails 4
PDF
Rails for Beginners - Le Wagon
ZIP
Rails 3 (beta) Roundup
PDF
Flexiblerails
PDF
What’s New in Rails 5.0?
PDF
RubyOnRails-Cheatsheet-BlaineKendall
PDF
RubyOnRails-Cheatsheet-BlaineKendall
PDF
Ruby on Rails - Introduction
PPTX
Intro to Rails 4
PDF
Ruby on-rails-workshop
PPTX
Learning to code for startup mvp session 3
PPTX
12 Introduction to Rails
PDF
What's new in Rails 4
PDF
Agile Web Development With Rails Third Edition Third Ruby Sam
KEY
Supa fast Ruby + Rails
PPT
PDF
Rails 3 : Cool New Things
Rails 4.0
Introduction to rails 4 v1
What's new in Rails 4
What's new in ruby on rails 4
Rails for Beginners - Le Wagon
Rails 3 (beta) Roundup
Flexiblerails
What’s New in Rails 5.0?
RubyOnRails-Cheatsheet-BlaineKendall
RubyOnRails-Cheatsheet-BlaineKendall
Ruby on Rails - Introduction
Intro to Rails 4
Ruby on-rails-workshop
Learning to code for startup mvp session 3
12 Introduction to Rails
What's new in Rails 4
Agile Web Development With Rails Third Edition Third Ruby Sam
Supa fast Ruby + Rails
Rails 3 : Cool New Things
Ad

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Electronic commerce courselecture one. Pdf
PDF
KodekX | Application Modernization Development
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Review of recent advances in non-invasive hemoglobin estimation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Programs and apps: productivity, graphics, security and other tools
Electronic commerce courselecture one. Pdf
KodekX | Application Modernization Development
Encapsulation_ Review paper, used for researhc scholars
Advanced methodologies resolving dimensionality complications for autism neur...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Dropbox Q2 2025 Financial Results & Investor Presentation
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

Riding Rails 4