Guest User

Untitled

a guest
Sep 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. How to chain try() and scoped to_s() in Rails?
  2. @model.try(:date)
  3.  
  4. @model.try(:date).try(:to_s)
  5.  
  6. @model.try(:date).try(:to_s(:long))
  7. @model.try(:date).try(:to_s).try(:long)
  8.  
  9. Person.try(:find, 1)
  10.  
  11. @model.try(:date).try(:to_s, :long)
  12.  
  13. @model.try(:date).try(:to_s(:long))
  14.  
  15. @model.try(:date).try(:to_s).try(:long)
  16.  
  17. @model.date.to_s(:long) rescue nil
  18.  
  19. l @model.date, format: :long rescue nil
Add Comment
Please, Sign In to add comment