Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 0.45 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ruby on rails 3 reload using cached data
  2. u = User.find(1)
  3. u.first_name
  4. #outputs bob
  5.  
  6. # manually change first_name for record 1 to jim with PGadmin or with rails console
  7.  
  8. u.reload
  9. u.valid?
  10. #outputs true
  11. u.first_name
  12. #outputs bob
  13.  
  14. #if i do this again
  15. u = User.find(1)
  16. #old data again
  17. u.first_name
  18. #outputs bob
  19.  
  20. #if i load data this way
  21. u = User.where('id = 1').first
  22. #new data
  23. u.first_name
  24. #outputs jim
  25.        
  26. ActiveRecord::Base.uncached do
  27.   User.find(1)
  28. end