Re: [Rails] Profiles
On Tue, Oct 22, 2013 at 4:27 PM, Orlando Hernandez
<ohernandez@unitecnica.net> wrote:
> I'm making a web app in which I am asked to register users, I did this
> already with Devise the problem is that I also create a profile for each
> user to register ... anyone have idea how to do?
There are two main ways to do this.
One very common way is to just tack more fields onto your User model.
This isn't very good, though, as your User model then fulfills
different duties: holding the credentials for logging in (the main
duty), holding whatever other profile-type info you want to store,
etc. Having the objects of one class fulfill a bunch of different
duties violates what Object Oriented people call the "Single
Responsibility Principle" (SRP), and makes it a "God Object" (very
powerful, yes, but usually so big, and with so much tight coupling
between the different duties, that it's very hard to maintain).
Much "cleaner" is to create another model, called something like
Profile, and have either Profile belong to User or vice-versa or both.
(Which way you do it may depend on things like whether you want one
User to be able to have multiple Profiles, or let multiple Users share
a Profile, or maybe even both. Assuming you want "one User, one
Profile", it probably won't matter much.)
-Dave
--
Dave Aronson, the T. Rex of Codosaurus LLC,
secret-cleared freelance software developer
taking contracts in or near NoVa or remote.
See information at http://www.Codosaur.us/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAHxKQiicdqgP3uCgy%2B4aG10As8LZ-SE3b7KP7gzGqAaVRVrJFA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home