RailsCasts Pro episodes are now free!
Learn more or hide this
i was curious about the interpolation of middle_name in the full_name method. why use interpolation there if 'middle_initial' (which i assume is a column in the db) would work too? is it b/c <pre>middle_initial + " " unless middle_initial.nil?</pre> wouldn't work? or would it?
this site is amazing, btw!
Concatonating strings like that will cause an error if middle_initial returns nil, which is why I chose to use string interpolation.
Hi Ryan, I think
name += middle_initial + ". " unless middle_initial.nil?
still work, won't cause any error even if middle_initial returns nil.
B/c the priority should be:
(name += middle_initial + ". ") unless middle_initial.nil?
Please let me know if I'm wrong.
[self.first_name, self.last_name].compact.join(' ')
This episode has been updated for Rails 5 as a blog post. Refactoring User Name in Rails 5 App
Users always make authority of blog because if you get followers than you work for them and share more things with them so they get knowledge and learn more with field of interest.I know some blogs like essayyard review they share lot's of knowledge to their users.
First sign in through GitHub to post a comment.