Your SlideShare is downloading. ×
0
RIDINGRAILS 4
#BCNONRAILS4
PHILIP DE SMEDT  @PHILIPDESMEDTPHILIPDESMEDT.COM
FREELANCEFULL-STACKDEVELOPER       (HIRE ME)
I WROTE A BOOK     UPGRADE TO RAILS 4
WHO HASTRIED RAILS 4?    gem install rails --version    4.0.0.beta1 --no-ri --no-rdoc
TURBOLINKS
CLICKLISTENS TO   EVENTS
LISTENS TO CLICK EVENTS      LOADS CONTENT    WITHOUT   RELOADING    THE PAGE
LISTENS TO CLICK EVENTSLOADS CONTENT WITHOUTRELOADING THE PAGE   REPLACES BODY+TITLE        HTML5     USING     pushState
DEMO
RUSSIAN DOLL CACHING
LET’S CACHEclass Post < ActiveRecord::Base has_many :categoriesendclass Category < ActiveRecord::Base belongs_to :post, to...
RAILS 3<!-- app/views/posts/show.html.erb --><% cache [„v1‟, @post] do %> <h1><%= @post.title %> categories:</h1> <ul><%= ...
RAILS 3<!-- app/views/categories/_category.html.erb --><% cache [„v1‟, category] do %> <li>   <%= category.title %>   <%= ...
RAILS 3 CACHE KEYS  views/v1/posts/1-  20130228151844
RAILS 3<!-- app/views/categories/_category.html.erb --><% cache [„v2  ‟, category] do %> <li>  <%= category.title %>  <%= ...
RAILS 3<!-- app/views/posts/show.html.erb --><% cache [„v2‟, @post] do %> <h1><%= @post.title %> categories:</h1> <ul><%= ...
<!-- app/views/posts/show.html.erb --><% cache @post do %> <h1><%= @post.title %> categories:</h1> <ul><%= render @post.ca...
RAILS 4 CACHE DIGESTviews/posts/1-20130228151844/fbda9857614e68ed1df453559a761d47
STRONG PARAMETERS
RAILS 3class User < ActiveRecord::Base     attr_accessible :name, :emailenddef create  @user = User.new(params[:user])  @u...
EXAMPLE
RAILS 4class CarsController < ApplicationController   def create           @car = Car.new(car_params)           if @car.sa...
private  def car_params   params.require(:car).permit(:name, :year, :brand)  endrequire(key) - Ensures that a parameter is...
LIVE STREAMING
ACTIONCONTROLLER::LIVEMIXIN I/O OBJECTSTREAM DATA TO CLIENT
DON’T USEWEBrickUSE PUMA OR RAINBOWS!
RUNS INSEPARATE THREAD
CLOSE YOURSTREAM WHEN    DONE
PUMA vs.RAINBOWS! vs.  NODE.JSRUBYSNIPPETS.COM
DEMO
ACTIVEMODEL::MODEL
FORM WITHOUTACTIVE RECORD.     WTF?
FORM_TAG  HELPERCREATE MODEL
EXAMPLE
class Contact   include ActiveModel::Model  attr_accessor :name, :email, :message  validates :name, presence: true  valida...
<h1>Contact Us</h1><%= form_for @contact do |f| %>  <%= f.label :name %>  <%= f.text_field :name %>  <%= f.label :email %>...
class ContactsController < ApplicationController    def new        @contact = Contact.new    end      def create          ...
LOTS OF OTHER STUFF  ROUTING CONCERNS          THREAD SAFETYCONTROLLER-WIDE E-TAGS        ENCRYPTED COOKIES               ...
EDUCATION IS BROKEN.I’LL BE TEACHING RAILS…            IN BARCELONA.          I <3 DEVBOOTCAMP/STARTER LEAGUE/…
COME SAY HI    PHILIP DE SMEDT            @PHILIPDESMEDT          PHILIPDESMEDT.COMLEANPUB.COM/UPGRADETORAILS4
Riding Rails 4
Riding Rails 4
Upcoming SlideShare
Loading in...5
×

Riding Rails 4

439

Published on

An overview of some of the new features in Rails 4. All features are discussed in depth in the e-book Upgrade to Rails 4 (http://www.leanpub.com/upgradetorails4) as well.

Published in: Technology, Education
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
439
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
15
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Transcript of "Riding Rails 4"

  1. 1. RIDINGRAILS 4
  2. 2. #BCNONRAILS4
  3. 3. PHILIP DE SMEDT @PHILIPDESMEDTPHILIPDESMEDT.COM
  4. 4. FREELANCEFULL-STACKDEVELOPER (HIRE ME)
  5. 5. I WROTE A BOOK UPGRADE TO RAILS 4
  6. 6. WHO HASTRIED RAILS 4? gem install rails --version 4.0.0.beta1 --no-ri --no-rdoc
  7. 7. TURBOLINKS
  8. 8. CLICKLISTENS TO EVENTS
  9. 9. LISTENS TO CLICK EVENTS LOADS CONTENT WITHOUT RELOADING THE PAGE
  10. 10. LISTENS TO CLICK EVENTSLOADS CONTENT WITHOUTRELOADING THE PAGE REPLACES BODY+TITLE HTML5 USING pushState
  11. 11. DEMO
  12. 12. RUSSIAN DOLL CACHING
  13. 13. LET’S CACHEclass Post < ActiveRecord::Base has_many :categoriesendclass Category < ActiveRecord::Base belongs_to :post, touch: trueend
  14. 14. RAILS 3<!-- app/views/posts/show.html.erb --><% cache [„v1‟, @post] do %> <h1><%= @post.title %> categories:</h1> <ul><%= render @post.categories %></ul><% end %>
  15. 15. RAILS 3<!-- app/views/categories/_category.html.erb --><% cache [„v1‟, category] do %> <li> <%= category.title %> <%= link_to “edit”, category %> </li><% end %>
  16. 16. RAILS 3 CACHE KEYS views/v1/posts/1- 20130228151844
  17. 17. RAILS 3<!-- app/views/categories/_category.html.erb --><% cache [„v2 ‟, category] do %> <li> <%= category.title %> <%= link_to “RENAME”, category %> </li><% end %>
  18. 18. RAILS 3<!-- app/views/posts/show.html.erb --><% cache [„v2‟, @post] do %> <h1><%= @post.title %> categories:</h1> <ul><%= render @post.categories %></ul><% end %>
  19. 19. <!-- 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 %>
  20. 20. RAILS 4 CACHE DIGESTviews/posts/1-20130228151844/fbda9857614e68ed1df453559a761d47
  21. 21. STRONG PARAMETERS
  22. 22. RAILS 3class User < ActiveRecord::Base attr_accessible :name, :emailenddef create @user = User.new(params[:user]) @user.saveend
  23. 23. EXAMPLE
  24. 24. RAILS 4class CarsController < ApplicationController def create @car = Car.new(car_params) if @car.save redirect_to @car else render „new‟ end endend
  25. 25. private def car_params params.require(:car).permit(:name, :year, :brand) endrequire(key) - Ensures that a parameter is present. If it‟s present,returns the parameter at the given key, otherwise raises anActionController:: ParameterMissing error.permit(filters) - Returns a new ActionController::Parametersinstance that includes only the given filtersand sets the permitted attribute for the object to true. This is usefulfor limiting which attributes should be allowed for mass updating.
  26. 26. LIVE STREAMING
  27. 27. ACTIONCONTROLLER::LIVEMIXIN I/O OBJECTSTREAM DATA TO CLIENT
  28. 28. DON’T USEWEBrickUSE PUMA OR RAINBOWS!
  29. 29. RUNS INSEPARATE THREAD
  30. 30. CLOSE YOURSTREAM WHEN DONE
  31. 31. PUMA vs.RAINBOWS! vs. NODE.JSRUBYSNIPPETS.COM
  32. 32. DEMO
  33. 33. ACTIVEMODEL::MODEL
  34. 34. FORM WITHOUTACTIVE RECORD. WTF?
  35. 35. FORM_TAG HELPERCREATE MODEL
  36. 36. EXAMPLE
  37. 37. 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 }endcontact = Contact.new(name: John Doe, email:john@doe.com, message: a test)
  38. 38. <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 %>
  39. 39. 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 endend
  40. 40. LOTS OF OTHER STUFF ROUTING CONCERNS THREAD SAFETYCONTROLLER-WIDE E-TAGS ENCRYPTED COOKIES HTTP PATCH VERB CUSTOM FLASH TYPESHTML5 FORM HELPERS SCHEMA CACHE DUMP PAGE/ACTION CACHING NO MORE OBSERVERS/SWEEPERS ACTIVE RESOURCE INDEX PAGE CONTROLLER
  41. 41. EDUCATION IS BROKEN.I’LL BE TEACHING RAILS… IN BARCELONA. I <3 DEVBOOTCAMP/STARTER LEAGUE/…
  42. 42. COME SAY HI PHILIP DE SMEDT @PHILIPDESMEDT PHILIPDESMEDT.COMLEANPUB.COM/UPGRADETORAILS4
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×