Hi all, I have a model user. A user has_many :roles Roles: admin, super admin, user This specific user has the admin role. But for a view I want to list all roles. Is it possible to do something like: "user.roles_all"? and get all the associated roles AND the ones not currently associated with the user? So I can create some checkboxes with the ones checked that are associated. I hope I''ve explained it right. Thanks in advance! -- 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-/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?hl=en -~----------~----~----~----~------~----~------~--~---
Role.find(:all) Leon Bogaert wrote:> Hi all, > > I have a model user. > A user has_many :roles > > Roles: admin, super admin, user > > This specific user has the admin role. But for a view I want to list all > roles. > Is it possible to do something like: > > "user.roles_all"? and get all the associated roles AND the ones not > currently associated with the user? > > So I can create some checkboxes with the ones checked that are > associated. > > I hope I''ve explained it right. > > Thanks in advance! >-- http://www.5valleys.com/ http://www.workingwithrails.com/person/8078 --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
do this in the controller @roles = Role.find :all and in the view use the @roles variable On Feb 1, 12:13 am, Leon Bogaert <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all, > > I have a model user. > A user has_many :roles > > Roles: admin, super admin, user > > This specific user has the admin role. But for a view I want to list all > roles. > Is it possible to do something like: > > "user.roles_all"? and get all the associated roles AND the ones not > currently associated with the user? > > So I can create some checkboxes with the ones checked that are > associated. > > I hope I''ve explained it right. > > Thanks in advance! > -- > Posted viahttp://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-/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?hl=en -~----------~----~----~----~------~----~------~--~---
ajaxrussia wrote:> do this in the controller > @roles = Role.find :all > > and in the view use the @roles variable > > > On Feb 1, 12:13 am, Leon Bogaert <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>And how would I now then which roles are associated with the user? That line only gets all the roles. -- 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-/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?hl=en -~----------~----~----~----~------~----~------~--~---