I''m in a dilemma. I have a users table. Each user has a role: admin, manager, agent, customer. What do you recommend about the users table? Options: 1) in the users table, add a role column, type string, and enter the role as a string. 2) in the users table, add a role_id column (integer, foreign key) that connects to a roles table. I know both ways would work, but I would like to know if one approach is better than the other and why. What has been your experience? --basic question from a newbie -- Posted via http://www.ruby-forum.com/. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
if string (text), use serialize and serialize your array of symbols to this
column
eg
USER_ROLES = {
:admin => "administrator",
:user => "Common user",
:guest => "guest user"
}
serialize :user_role
and use :user_role as array of roles
or
another table has advantage of some changing, holding other properties (as human
name, description, etc)...
On Jul 25, 2011, at 20:16 , Leonel *.* wrote:
> I''m in a dilemma. I have a users table. Each user has a role:
admin,
> manager, agent, customer.
>
> What do you recommend about the users table? Options:
> 1) in the users table, add a role column, type string, and enter the
> role as a string.
> 2) in the users table, add a role_id column (integer, foreign key) that
> connects to a roles table.
>
> I know both ways would work, but I would like to know if one approach is
> better than the other and why. What has been your experience?
>
> --basic question from a newbie
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
--
==============================================================================Tomas
Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache
www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz
==============================================================================
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
If you''re making a roles system on your own, I''d recommend using cancan by Ryan Bates instead. It''s very powerful, and integrates with popular authentication libraries out-of-the-box. cancan => https://github.com/ryanb/cancan On 7/25/11, Tom Meinlschmidt <tomas-ooGa/4BNRfTT2+6r9I86XQ@public.gmane.org> wrote:> if string (text), use serialize and serialize your array of symbols to this > column > > eg > > USER_ROLES = { > :admin => "administrator", > :user => "Common user", > :guest => "guest user" > } > > serialize :user_role > > and use :user_role as array of roles > > or > > another table has advantage of some changing, holding other properties (as > human name, description, etc)... > > On Jul 25, 2011, at 20:16 , Leonel *.* wrote: > >> I''m in a dilemma. I have a users table. Each user has a role: admin, >> manager, agent, customer. >> >> What do you recommend about the users table? Options: >> 1) in the users table, add a role column, type string, and enter the >> role as a string. >> 2) in the users table, add a role_id column (integer, foreign key) that >> connects to a roles table. >> >> I know both ways would work, but I would like to know if one approach is >> better than the other and why. What has been your experience? >> >> --basic question from a newbie >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> -- >> 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > ==============================================================================> Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache > > www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz > ==============================================================================> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I think you could use STI (single table inheritance) and create a class for each role. Best regards, Everaldo On Mon, Jul 25, 2011 at 3:25 PM, Tom Meinlschmidt <tomas-ooGa/4BNRfTT2+6r9I86XQ@public.gmane.org>wrote:> if string (text), use serialize and serialize your array of symbols to this > column > > eg > > USER_ROLES = { > :admin => "administrator", > :user => "Common user", > :guest => "guest user" > } > > serialize :user_role > > and use :user_role as array of roles > > or > > another table has advantage of some changing, holding other properties (as > human name, description, etc)... > > On Jul 25, 2011, at 20:16 , Leonel *.* wrote: > > > I''m in a dilemma. I have a users table. Each user has a role: admin, > > manager, agent, customer. > > > > What do you recommend about the users table? Options: > > 1) in the users table, add a role column, type string, and enter the > > role as a string. > > 2) in the users table, add a role_id column (integer, foreign key) that > > connects to a roles table. > > > > I know both ways would work, but I would like to know if one approach is > > better than the other and why. What has been your experience? > > > > --basic question from a newbie > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > -- > > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > > ==============================================================================> Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache > > www.meinlschmidt.com www.maxwellrender.cz www.lightgems.cz > > ==============================================================================> > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.