Closed ansary14-zz closed 3 years ago
Here is Heroku log file finance-tracker-ayub-logs-1606417452520.txt
could you share the code that renders the name
<li class="nav-item user-name"> <%= fa_icon 'user' %> <%= current_user.full_name %> </li>
def full_name
return "#{first_name} #{last_name}" if first_name || last_name
"Anonymous"
end
this application created with help by devise gem
could you share the first_name and last_name of the user from rails console on Heroku,
e.g. User.find(:id).first_name
and User.find(:id).last_name
In Heroku rails console both are nil. All the users first_name and the last_name are nil
def full_name return "#{first_name} #{last_name}" if first_name || last_name "Anonymous" end
thats the reason why full_name returned Anonymous
according to the logic, "#{first_name} #{last_name}"
will be returned only when at least one of first_name or last_name are non-nil values.
that also implies if at least of them are empty string, still "#{first_name} #{last_name}"
will be used
could you clarify when you would like to see "#{first_name} #{last_name}"
and when Anonymous?
When I send you a peek video. This time I update profile (Edit profile) with first name And last name But after the update button press, it shows the message that updated successfully but the full name doesn't show.
But now when I repeat the process again in Heroku Then it returns the full name. I didn't change anything....!
so its now working, you think?
could you clarify when you would like to see
"#{first_name} #{last_name}"
and when Anonymous?
When the user has a first name or last name then it shows the full name (first name or last name or both) If both missing then Anynomous
so its now working, you think?
Yes It's now working
I think I need some patient after Heroku push
could you clarify when you would like to see
"#{first_name} #{last_name}"
and when Anonymous?When the user has a first name or last name then it shows the full name (first name or last name or both) If both missing then Anynomous
ok its clear. nevertheless, you should care about the empty string too.
when you submit the form with empty values, empty strings ''
are inserted in place of nil
in the corresponding fields.
the following logic will match nil values but fail on empty strings
if first_name || last_name
if you want to match either nil or empty strings, you have to write it as
if first_name.present? || last_name.present?
I would have written the logic as
def full_name
name = [first_name.presence, last_name.presence].compact.join(' ').presence
name || 'Anonymous'
end
cc @ansary14
Local host shows full name perfectly. After editing the profile.
But Heroku didn't show, its show Anonymous which was for such case where a first name or last name doesn't set by the user.