[LRUG] Setting default roles in a user record

James Adam james.adam at gmail.com
Tue Aug 7 01:53:02 PDT 2007


Or, sidestep the whole "initialization" issue:

  class User < ActiveRecord::Base
    def self.create_with_default_roles(*attributes)
      new_user = new(*attributes)
      Roles.find_all_default_roles.each do |role| # or whatever
        new_user.roles << role
      end
    end
    # etc...
  end

My point is, you don't need this to happen *automagically*. Just
define a new method that does what you want, and call it wherever you
want this default user created.

- James

On 8/7/07, Pratik Naik <pratik at thinkwares.com> wrote:
> Or may be you can derive bits and pieces from my patch at
> http://dev.rubyonrails.org/ticket/9093
>
> On 8/7/07, Andrew Stewart <boss at airbladesoftware.com> wrote:
> >
> > On 7 Aug 2007, at 09:02, John Winters wrote:
> > > The best solution I've thought of so far is to add a set_defaults
> > > method
> > > to the model and invoke that at the appropriate point in the
> > > controller,
> > > but is that the right way to do it?
> >
> > Check this out:
> >
> > http://drawohara.tumblr.com/post/6677354
> >
> > Regards,
> > Andy Stewart
> >
> > _______________________________________________
> > Chat mailing list
> > Chat at lists.lrug.org
> > http://lists.lrug.org/listinfo.cgi/chat-lrug.org
> >
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>


-- 
* J *
  ~



More information about the Chat mailing list