# User and Account models

**URL:** <https://www.ruby-forum.com/t/user-and-account-models/145438>\
**Category:** Rails\
**Created:** [August 9, 2008, 11:29am UTC](https://www.ruby-forum.com/t/user-and-account-models/145438 "2008-08-09T11:29:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 9, 2008, 11:29am UTC](https://www.ruby-forum.com/t/user-and-account-models/145438/1 "2008-08-09T11:29:31Z")

</div>

This has probably been asked a few times before but I can’t find a  
definite answer to my angle: The app has a User model which only keeps  
the account-esque information about the user, e.g. email and password,  
and nothing else. The Profile model is used to hold the data we use on a  
regular basis, like first name, last name, etc. I’ve head people saying  
that it’s good practice to keep these two types of data separated.

Because the regularly accessed user data is stored in the Profile model,  
we’re often calling @user.profile.some\_attribute, and this is making  
things a little messy - I’d much rather be calling @user.some\_attribute  
for data which we seem to be accessing all the time. So, would it be  
wise to change things round a bit and to have an Account model for the  
account data and use the User model for the data we access all the time?

I’m still new to Rails and web dev in general (haven’t deployed a single  
Rails app yet), so I don’t know if this is a really bad idea; based on  
any experiences you have with authenticating users, would this route  
work?

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 9, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/user-and-account-models/145438/2 "2008-08-09T12:40:51Z")

</div>

On 09 Aug 2008, at 11:29, Neil C. wrote:

> model,  
> Rails app yet), so I don’t know if this is a really bad idea; based on  
> any experiences you have with authenticating users, would this route  
> work?

You can expose certain attributes in a related record by doing:

class User \< ActiveRecord::Base

```
has_one :profile, :dependent => :destroy

delegate :first_name, :to => :profile
delegate :last_name, :to => :profile

```

end

It will allow you to access those attributes as @user.first\_name,  
@user.last\_name.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 9, 2008, 1:20pm UTC](https://www.ruby-forum.com/t/user-and-account-models/145438/3 "2008-08-09T13:20:49Z")

</div>

Peter De Berdt wrote:

> On 09 Aug 2008, at 11:29, Neil C. wrote:
> 
> > model,  
> > Rails app yet), so I don’t know if this is a really bad idea; based on  
> > any experiences you have with authenticating users, would this route  
> > work?
> 
> You can expose certain attributes in a related record by doing:
> 
> class User \< ActiveRecord::Base
> 
> ```
> has_one :profile, :dependent => :destroy
> 
> delegate :first_name, :to => :profile
> delegate :last_name, :to => :profile
> 
> ```
> 
> end
> 
> It will allow you to access those attributes as @user.first\_name,  
> @user.last\_name.
> 
> Best regards
> 
> Peter De Berdt

Thanks Peter. I like the sound of that. I’m actually stuck with how to  
deal with the validations on the user sign-up. The user.profile is built  
in an after\_create on the user model (implemented by someone else at the  
beginning of the project) and I still haven’t worked out how to validate  
on the profile model attributes which are required at sign-up, including  
both first name and last name. Would the delegate method handle this?

---

<div class="post-metadata">

**Author:** ![chunkyslink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f0a364/32.png) [@chunkyslink](https://www.ruby-forum.com/u/chunkyslink)\
**Post date:** [August 9, 2008, 2:54pm UTC](https://www.ruby-forum.com/t/user-and-account-models/145438/4 "2008-08-09T14:54:15Z")

</div>

On 09 Aug 2008, at 13:20, Neil C. wrote:

> > 
> 
> built  
> in an after\_create on the user model (implemented by someone else at  
> the  
> beginning of the project) and I still haven’t worked out how to  
> validate  
> on the profile model attributes which are required at sign-up,  
> including  
> both first name and last name. Would the delegate method handle this?

[http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001055](http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M001055)

I’d suggest picking up a book or two on Rails, all the information you  
need will be in there and it will make the workings of the framework a  
lot clearer.

Best regards

Peter De Berdt
