Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a profile for users model in rails

I have a users model in my rails application. It has a name attribute only along with email & password added to it for login via Devise. I want to create a model Profile for users. How shall I create it. Either by adding profile attributes to existing User model or by creating a model Profile and adding a belongs_to association to it.

like image 636
Metal Avatar asked Dec 20 '22 18:12

Metal


1 Answers

Adding more attributes to your user model will make your user object a bit heavy and is not the best idea given that you'll be calling that object quite often. For instance, to verify a user, you don't need to load the profile attributes like location or date of birth, which the current_user helper would. So, its better to extract profile attributes in a separate model and adopt either of gabreilhilal's approaches.

like image 176
rb512 Avatar answered Jan 04 '23 03:01

rb512