VHanded
VHanded

Reputation: 2089

Adding A LOT Attributes to Rails Devise

I am implementing a login system, which require to collect a lot of user data, for example:

college, course, graduate year, start year, hobby, .... about 20-30 of them.

Is it wise to put them all into Devise? Or create another Model to handle that?

Upvotes: 0

Views: 57

Answers (2)

Kalpesh Fulpagare
Kalpesh Fulpagare

Reputation: 1299

Its not good idea to put so much of data in devise model. Devise model record is always fetched from database for every request.(You can see it from logs)
You can add it in another model and add association.
e.g. you can add profile model
Assuming you have User model as devise model.
You have to take care of creating profile record after either User creation or User logs in first time or as per your requirement.

class User < ActiveRecord::Base
  has_one   :profile, :dependent => :destroy
end

class Profile < ActiveRecord::Base
  belongs_to   :user
end

Upvotes: 1

Rajdeep Singh
Rajdeep Singh

Reputation: 17834

You can create a user_info model with this association, in user.rb

has_one :user_info

On, sign_in it should create an instance of user_info if its not present in the databse This approach would be better if you want to add 20-30 columns

Upvotes: 0

Related Questions