1

I'm outputting the user's First+Last name by using: =current_user.try(:first_name)+" "+current_user.try(:last_name)

However, if they're both nil, I get an error for trying to add a space between two nil values.

What's a better way to handle this issue??

Kevin Brown
  • 12,602
  • 34
  • 95
  • 155

1 Answers1

0

It would be better keep the logic out of the view by moving the full name logic into the model:

class User < ActiveRecord::Base
  def full_name
    [first_name, last_name].compact.join(' ')
  end
end

Then use it in your view:

= current_user.full_name
infused
  • 24,000
  • 13
  • 68
  • 78