Take the 2-minute tour ×  I'm fairly new to rails, working on a
Rails 3 app with a Profile model for users.  In the profile
Model I'd like to have a "name" entry, and I'd like to be able
to access logical variations of it using simple syntax like:
user.profile.name = "John Doe" user.profile.name.first = "John"
user.profile.name.last = "Doe"  Is this possible, or do I need
to stick with "first_name" and "last_name" as my fields in this
model?  share|improve this question add comment  4 Answers  up
vote 9 down vote accepted  It's possible, but I wouldn't
recommend it.  I would just stick with first_name and last_name
if I were you and add a method fullname:  def fullname
"#{first_name} #{last_name}"   If you really do want
user.profile.name, you could create a Name model like this:
class Name < ActiveRecord::Base   belongs_to :profile    def
to_s     "#{first} #{last}"  This allows you to do:
user.profile.name.to_s  # John Doe user.profile.name.first #
John user.profile.name.last  # Doe share|improve this