Riding Rails 4
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Riding Rails 4

  • 524 views
Uploaded 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.

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.

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
524
On Slideshare
524
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
13
Comments
0
Likes
2

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. RIDINGRAILS 4
  • 2. #BCNONRAILS4
  • 3. PHILIP DE SMEDT @PHILIPDESMEDTPHILIPDESMEDT.COM
  • 4. FREELANCEFULL-STACKDEVELOPER (HIRE ME)
  • 5. I WROTE A BOOK UPGRADE TO RAILS 4
  • 6. WHO HASTRIED RAILS 4? gem install rails --version 4.0.0.beta1 --no-ri --no-rdoc
  • 7. TURBOLINKS
  • 8. CLICKLISTENS TO EVENTS
  • 9. LISTENS TO CLICK EVENTS LOADS CONTENT WITHOUT RELOADING THE PAGE
  • 10. LISTENS TO CLICK EVENTSLOADS CONTENT WITHOUTRELOADING THE PAGE REPLACES BODY+TITLE HTML5 USING pushState
  • 11. DEMO
  • 12. RUSSIAN DOLL CACHING
  • 13. LET’S CACHEclass Post < ActiveRecord::Base has_many :categoriesendclass Category < ActiveRecord::Base belongs_to :post, touch: trueend
  • 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. RAILS 3<!-- app/views/categories/_category.html.erb --><% cache [„v1‟, category] do %> <li> <%= category.title %> <%= link_to “edit”, category %> </li><% end %>
  • 16. RAILS 3 CACHE KEYS views/v1/posts/1- 20130228151844
  • 17. RAILS 3<!-- app/views/categories/_category.html.erb --><% cache [„v2 ‟, category] do %> <li> <%= category.title %> <%= link_to “RENAME”, category %> </li><% end %>
  • 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. <!-- 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. RAILS 4 CACHE DIGESTviews/posts/1-20130228151844/fbda9857614e68ed1df453559a761d47
  • 21. STRONG PARAMETERS
  • 22. RAILS 3class User < ActiveRecord::Base attr_accessible :name, :emailenddef create @user = User.new(params[:user]) @user.saveend
  • 23. EXAMPLE
  • 24. RAILS 4class CarsController < ApplicationController def create @car = Car.new(car_params) if @car.save redirect_to @car else render „new‟ end endend
  • 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. LIVE STREAMING
  • 27. ACTIONCONTROLLER::LIVEMIXIN I/O OBJECTSTREAM DATA TO CLIENT
  • 28. DON’T USEWEBrickUSE PUMA OR RAINBOWS!
  • 29. RUNS INSEPARATE THREAD
  • 30. CLOSE YOURSTREAM WHEN DONE
  • 31. PUMA vs.RAINBOWS! vs. NODE.JSRUBYSNIPPETS.COM
  • 32. DEMO
  • 33. ACTIVEMODEL::MODEL
  • 34. FORM WITHOUTACTIVE RECORD. WTF?
  • 35. FORM_TAG HELPERCREATE MODEL
  • 36. EXAMPLE
  • 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. <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. 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. 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. EDUCATION IS BROKEN.I’LL BE TEACHING RAILS… IN BARCELONA. I <3 DEVBOOTCAMP/STARTER LEAGUE/…
  • 42. COME SAY HI PHILIP DE SMEDT @PHILIPDESMEDT PHILIPDESMEDT.COMLEANPUB.COM/UPGRADETORAILS4