Blow up when things are wrong
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Blow up when things are wrong

on

  • 222 views

When something unexpected happens, you should know about it immediately to make debugging and fixing the problem easier. Discusses ActiveRecord persistence APIs.

When something unexpected happens, you should know about it immediately to make debugging and fixing the problem easier. Discusses ActiveRecord persistence APIs.

Statistics

Views

Total Views
222
Views on SlideShare
222
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Blow up when things are wrong Presentation Transcript

  • 1. Blow up whenthings are wrongActiveRecord editionVesa Vänskä, Kisko LabsHelsinki Ruby Brigade, Rails Girls
  • 2. When somethingis wrong, youshould knowabout it as fast aspossible
  • 3. #save vs #save!
  • 4. foo.save!# orif foo.save# successelse# failend
  • 5. The case ofupdatingattributes
  • 6. Validations Callbacks#update_attributes ✔ ✔#update_attribute ✖ ✔
  • 7. Question
  • 8. Which of #decrement,#decrement!, and#decrement_counterskip validations/callbacks?
  • 9. Validations Callbacks#decrement ✔ ✖#decrement! ✖ ✔#decrement_counter ✖ ✖
  • 10. http://guides.rubyonrails.org/active_record_validations_callbacks.html
  • 11. ATKDo Not WantRubyGemhttps://github.com/garybernhardt/do_not_want
  • 12. Making it simpler
  • 13. In Rails 3.2.7 the#update_attribute method wasactually deprecated
  • 14. 14.6.2012 – #update_attribute is deprecated in 3.2branch14.6.2012 – #update_attribute was removed from 4.0branch24.7.2012 – #update_column was deprecated in 4.0branch26.7.2012 – Rails 3.2.7 release30.7.2012 – #update_column is undeprecated in 4.0branch1.8.2012 – #update_attribute is undeprecated in 3.2branch25.8.2012 – #update_attribute is put back in 4.0branch9.8.2012 – Rails 3.2.8 release
  • 15. • https://github.com/rails/rails/commit/b081f6b59fb3f15d12043072ad9b331ffd2bc56e• https://github.com/rails/rails/pull/6738• https://github.com/rails/rails/pull/1190• https://github.com/rails/rails/commit/4ac81de52fbcdabc68f6d1fa8a5ee9ff7fff7df1• https://github.com/rails/rails/commit/50bdb924ba26999a468ec4844917cefec39ba08c• https://github.com/rails/rails/commit/81542f95d25825a7d3eff87d6f706661bf553b18Links
  • 16. I
  • 17. What is thecurrent status?
  • 18. After all this•In Rails 4 the recommended wayis to use #update with a hash•#update_attributes is aliased to#update•#update_attribute is still skippingvalidations
  • 19. Vesas laws ofupdating attributes1. Use #update_attributes or usesetters and #save/#save!2. All other methods of updatingattributes need an accompanyingcomment that explains why youdidnt follow the first rule.
  • 20. Useless ActiveResourceinformation•ActiveResource #update_attributewill run validations normally
  • 21. Extra Ruby tip
  • 22. {foo: "bar"}[:foo]{foo: "bar"}.fetch(:foo)
  • 23. {foo: "bar"}[:foo] #=> "bar"{foo: "bar"}.fetch(:foo)#=> "bar"
  • 24. {foo: "bar"}[:whatevs]{foo: "bar"}.fetch(:whatevs)
  • 25. {foo: "bar"}[:whatevs] #=> nil{foo: "bar"}.fetch(:whatevs)#=> KeyError: key notfound: :whatevs
  • 26. {foo: "bar"}.fetch(:whatevs, :not_found)#=> :not_found{foo: "bar"}.fetch(:whatevs) { 1 + 1 }#=> 2
  • 27. Thank you!twitter.com/vesanvesavanska.com