what's new in rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

41
Hello #VANRUBY!

Upload: godfrey-chan

Post on 10-May-2015

2.971 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Hello #VANRUBY!

Page 2: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Godfrey Chan @chancancode

Page 3: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)
Page 4: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)
Page 5: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

PUBLIC SERVICEANNOUNCEMENT

Page 6: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

RAILS 3.2.16 + 4.0.2http://groups.google.com/group/rubyonrails-security

Page 7: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

What’s NEW INRails 4.1 *

* As OF 752f9fed00221ad97073e13b12be9c849199b4b8

Page 8: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

VARIANTS

Page 9: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Variants

Page 10: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Variantsclass ApplicationController < ActionController::Base before_action :detect_variant  private  def detect_variant request.variant = \ case request.user_agent when /iPhone/ then :phone when /iPad/ then :tablet end endend

respond_to do |format| format.html do |html| html.phone # index.html+phone.erb html.tablet do # index.html+tablet.erb # ... render end endend

Page 11: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

VariantsOTHER USES...A/B TESTING?

API VERSIONING?OLD BROWSERS?NO JS FALLBACK?

Page 12: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

ENUMS

Page 13: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

ENUMSclass Conversation < ActiveRecord::Base enum status: [ :active, :archived ]end conversation.archive!conversation.active? # => falseconversation.status # => "archived" Conversation.archived # => Relation for all archived Conversations

Page 14: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

MESSAGE VERIFIER

Page 15: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

MESSAGE VERIFIERmessage = Rails.application .message_verifier('salt') .generate('my sensible data') Rails.application .message_verifier('salt') .verify(message) # => 'my sensible data'

Page 16: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

MESSAGE VERIFIERUSES...

PASSWORD RESET?INVITE TOKEN?

OTHER LINKS IN EMAILS?

Page 17: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

TIME TRAVEL

Page 18: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

TIME TRAVEL

Page 19: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

TIME TRAVELtest "Fast forward to Christmas" do refute is_it_christmas_yet? travel_to Time.new(2013, 12, 25, 00, 00, 00) assert is_it_christmas_yet?end test "How I met your mother" do @mother = User.find(...) travel -30.years do assert @mother.single? end refute @mother.single?end

Page 20: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

SPRING

Page 21: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Rails application preloader

Page 22: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Totally AutomatICGIc

Page 23: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

spring$ time ./bin/rails runner 'puts "Hello"'Hello0.05s user 0.02s system 1% cpu 3.860 total

$ time ./bin/rails runner 'puts "Hello"'Hello0.05s user 0.01s system 27% cpu 0.229 total

$ time ./bin/rake spec......................................................................................................................................... Finished in 15.04 seconds322 examples, 0 failures 0.06s user 0.02s system 0% cpu 25.446 total $ time ./bin/rake spec......................................................................................................................................... Finished in 14.79 seconds322 examples, 0 failures 0.05s user 0.01s system 0% cpu 20.543 total

Page 24: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

spring

Page 25: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

NO TOUCHING

Page 26: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

NO TOUCHINGActiveRecord::Base.no_touching do Post.first.touch # does nothingend Comment.no_touching do Comment.first.touch # does nothing Post.first.touch # updates, but won't update related comments if there are anyend

Page 27: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

TO_PARAM

Page 28: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

TO_PARAMclass User < ActiveRecord::Base to_param :nameend user = User.find_by(name: 'Fancy Pants')user.id # => 123user.to_param # => "123-fancy-pants"

_

Page 29: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

String#Remove

Page 30: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

String#Remove>> ' a lot of whitespace '.remove(/[:space:]/)=> "alotofwhitespace"

>> 'username=godfrey&password=123456'.remove(/&?password=[^&]*/)=> "username=godfrey"

Page 31: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

JSON

Page 32: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

r.i.p. multijson

Page 33: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

all-New JSON encoder

Page 34: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Action view

Page 35: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

SURPRISES?

Page 36: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

TRY IT TODAYhttps://gist.github.com/chancancode/7781341

Page 37: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

TRY IT TODAY# Gemfilegem 'rails', github: 'rails/rails'gem 'arel', github: 'rails/arel'

Page 38: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

#VANRUBY + OSS= <3 <3 <3 <3

Page 39: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Hack night TUE dec 17

Page 40: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

IRC #VANRUBY (freenode)

Page 41: What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)

Godfrey Chan @chancancode