And if user can potentially be nil, you can also use user.try(:presence) || ""
This will avoid "undefined method 'presence' for nil:NilClass" errors. On 10 Sep 2010, at 10:27, Christiaan Van den Poel wrote:
user.presence || "" see http://rubydoc.info/docs/rails/3.0.0/Object:presence On Fri, Sep 10, 2010 at 10:25 AM, Mauro <mrsan...@gmail.com> wrote: If you know grails, there is a feature like this: <% user.name? %> that prevents to chek if the value is null or not. In rails view I have to do <% if user.name %> <%= user.name %> <% end %> to display user.name if it is not nil. There is a shortcut or some feature like that in grails?
Best regards Peter De Berdt -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.