Last active
December 14, 2015 17:59
-
-
Save manusajith/5125763 to your computer and use it in GitHub Desktop.
In Rails, try() lets you call methods on an object without having to worry about the possibility of that object being nil and thus raising an exception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user_details = User.find(id).try(:user_details).try(:first_name) | |
#no need to worry if user_details is nill |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment