Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Hello #VANRUBY!
Godfrey Chan
  @chancancode
PUBLIC SERVICE
ANNOUNCEMENT
RAILS 3.2.16 + 4.0.2
http://groups.google.com/group/rubyonrails-security
What’s NEW IN
Rails 4.1 *
* As OF 752f9fed00221ad97073e13b12be9c849199b4b8
VARIANTS
Variants
Variants
class ApplicationController < ActionController::Base
before_action :detect_variant
 
private
 
def detect_variant...
Variants

OTHER USES...
A/B TESTING?
API VERSIONING?
OLD BROWSERS?
NO JS FALLBACK?
ENUMS
ENUMS
class Conversation < ActiveRecord::Base
enum status: [ :active, :archived ]
end
conversation.archive!
conversation.a...
MESSAGE VERIFIER
MESSAGE VERIFIER
message = Rails.application
.message_verifier('salt')
.generate('my sensible data')
 
Rails.application
....
MESSAGE VERIFIER
USES...
PASSWORD RESET?
INVITE TOKEN?
OTHER LINKS IN EMAILS?
TIME TRAVEL
TIME TRAVEL
TIME TRAVEL
test "Fast forward to Christmas" do
refute is_it_christmas_yet?
travel_to Time.new(2013, 12, 25, 00, 00, 00)
a...
SPRING
Rails application preloader
Totally AutomatICGIc
spring
$ time ./bin/rails runner 'puts "Hello"'
Hello
0.05s user 0.02s system 1% cpu 3.860 total
$ time ./bin/rails runner...
spring
NO TOUCHING
NO TOUCHING
ActiveRecord::Base.no_touching do
Post.first.touch # does nothing
end
 
Comment.no_touching do
Comment.first.t...
TO_PARAM
_
TO_PARAM
class User < ActiveRecord::Base
to_param :name
end
 
user = User.find_by(name: 'Fancy Pants')
user.id
# => 123
...
String#Remove
String#Remove
>> ' a lot of
whitespace
=> "alotofwhitespace"

'.remove(/[:space:]/)

>> 'username=godfrey&password=123456'...
JSON
r.i.p. multijson
all-New JSON encoder
Action view
SURPRISES?
TRY IT TODAY

https://gist.github.com/chancancode/7781341
TRY IT TODAY
# Gemfile
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
#VANRUBY + OSS
= <3 <3 <3 <3
Hack night TUE dec 17
IRC #VANRUBY (freenode)
Godfrey Chan
  @chancancode
What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)
What's new in Rails 4.1 (as of 752f9fed00221ad97073e13b12be9c849199b4b8)
Upcoming SlideShare
Loading in …5
×

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

4,099 views

Published on

Published in: Technology, Education

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

  1. 1. Hello #VANRUBY!
  2. 2. Godfrey Chan   @chancancode
  3. 3. PUBLIC SERVICE ANNOUNCEMENT
  4. 4. RAILS 3.2.16 + 4.0.2 http://groups.google.com/group/rubyonrails-security
  5. 5. What’s NEW IN Rails 4.1 * * As OF 752f9fed00221ad97073e13b12be9c849199b4b8
  6. 6. VARIANTS
  7. 7. Variants
  8. 8. Variants class 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 end end respond_to do |format| format.html do |html| html.phone # index.html+phone.erb html.tablet do # index.html+tablet.erb # ... render end end end
  9. 9. Variants OTHER USES... A/B TESTING? API VERSIONING? OLD BROWSERS? NO JS FALLBACK?
  10. 10. ENUMS
  11. 11. ENUMS class Conversation < ActiveRecord::Base enum status: [ :active, :archived ] end conversation.archive! conversation.active? # => false conversation.status # => "archived" Conversation.archived # => Relation for all archived Conversations
  12. 12. MESSAGE VERIFIER
  13. 13. MESSAGE VERIFIER message = Rails.application .message_verifier('salt') .generate('my sensible data')   Rails.application .message_verifier('salt') .verify(message) # => 'my sensible data'
  14. 14. MESSAGE VERIFIER USES... PASSWORD RESET? INVITE TOKEN? OTHER LINKS IN EMAILS?
  15. 15. TIME TRAVEL
  16. 16. TIME TRAVEL
  17. 17. TIME TRAVEL test "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
  18. 18. SPRING
  19. 19. Rails application preloader
  20. 20. Totally AutomatICGIc
  21. 21. spring $ time ./bin/rails runner 'puts "Hello"' Hello 0.05s user 0.02s system 1% cpu 3.860 total $ time ./bin/rails runner 'puts "Hello"' Hello 0.05s user 0.01s system 27% cpu 0.229 total $ time ./bin/rake spec .............................................................................................   Finished in 15.04 seconds 322 examples, 0 failures   0.06s user 0.02s system 0% cpu 25.446 total   $ time ./bin/rake spec .............................................................................................   Finished in 14.79 seconds 322 examples, 0 failures   0.05s user 0.01s system 0% cpu 20.543 total
  22. 22. spring
  23. 23. NO TOUCHING
  24. 24. NO TOUCHING ActiveRecord::Base.no_touching do Post.first.touch # does nothing end   Comment.no_touching do Comment.first.touch # does nothing Post.first.touch # updates, but won't update related comments if there are any end
  25. 25. TO_PARAM
  26. 26. _ TO_PARAM class User < ActiveRecord::Base to_param :name end   user = User.find_by(name: 'Fancy Pants') user.id # => 123 user.to_param # => "123-fancy-pants"
  27. 27. String#Remove
  28. 28. String#Remove >> ' a lot of whitespace => "alotofwhitespace" '.remove(/[:space:]/) >> 'username=godfrey&password=123456'.remove(/&?password=[^&]*/) => "username=godfrey"
  29. 29. JSON
  30. 30. r.i.p. multijson
  31. 31. all-New JSON encoder
  32. 32. Action view
  33. 33. SURPRISES?
  34. 34. TRY IT TODAY https://gist.github.com/chancancode/7781341
  35. 35. TRY IT TODAY # Gemfile gem 'rails', github: 'rails/rails' gem 'arel', github: 'rails/arel'
  36. 36. #VANRUBY + OSS = <3 <3 <3 <3
  37. 37. Hack night TUE dec 17
  38. 38. IRC #VANRUBY (freenode)
  39. 39. Godfrey Chan   @chancancode

×