i have a field which is not required i.e. can be nil. i want to use the ffg: myfield.html_safe in my view. this doesn't work for the items that have no myfield. i get an exception, how do i get html_safe to apply only if the field is defined? thanks
In Rails, you can use
myfield.try(:html_safe)
Docs: http://api.rubyonrails.org/classes/Object.html#method-i-try
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With