Devise for Rails 4: why should you keep user profi

2019-06-20 06:14发布

问题:

I'm using devise and as per the documentations recommendations I have a User model (for devise) and a Profile model for user data such as names, job etc. Why is it considered "not so good" to just store all these attributes on the devise User model table. Just curious.

回答1:

Adding fields to tables specified by an external source could result in migration errors in future versions of the gem if the gem changes the table definition.

Think of the users table as an implementation detail of the devise gem. It's generally a bad idea to modify the source of an external library because it makes upgrades difficult or impossible.



回答2:

Separation of concern! The User model is used by devise (which handles app auth and access) while the Profile model handles all the business logic.