Robert Gabaree
2006-Sep-16 12:25 UTC
Best way to set up user preferences for multiple users?
I have a User model that contains all of the users'' account information, but now I''d like to give each user their own set of preferences. Using a database, what''s the "best" solution to this? I was thinking of setting up a Preference model with something along these lines: id, user_id, preference_value_1, preference_value_2, etc. And then for the relationship, doing something like: class User has_one :preference end class Preference has_one :user end Is this the right way to go about doing this, or is there a better way? Thanks, Rob --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Jon Gretar Borgthorsson
2006-Sep-16 13:04 UTC
Re: Best way to set up user preferences for multiple users?
Personally I go for the parameter, value type. And then add a special get_prefs and set_prefs methods to ie. id, user_id, pref_name, value class User has_many :preferences def get_pref(pref_name) {//returns strinf} def set_pref(pref_name, value) {//returns bool} class Preference belongs_to :user On 9/16/06, Robert Gabaree <lists-n9Q/XG8udXg@public.gmane.org> wrote:> > I have a User model that contains all of the users'' account > information, but now I''d like to give each user their own set of > preferences. Using a database, what''s the "best" solution to this? > > I was thinking of setting up a Preference model with something along > these lines: > > id, user_id, preference_value_1, preference_value_2, etc. > > And then for the relationship, doing something like: > > class User > has_one :preference > end > > class Preference > has_one :user > end > > Is this the right way to go about doing this, or is there a better way? >-- -------------- Jon Gretar Borgthorsson http://www.jongretar.net/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---