Add new user data into another database as well...

9 views
Skip to first unread message

Bruce

unread,
Feb 12, 2012, 6:05:01 PM2/12/12
to Devise
I currently have this as the Registration Controller for Devise

class RegistrationsController < Devise::RegistrationsController

protected

def after_update_path_for(resource)
edit_user_registration_path
end
end

I want to enter in certain fields (company_name, user_id that was
created) into a database called Company because I want to create
multiple users for each company.

Do you know how to write this in the Devise controller?

Carlos Antonio da Silva

unread,
Feb 12, 2012, 8:57:40 PM2/12/12
to plataforma...@googlegroups.com
If you're talking about default attributes for your user, you could probably override the `build_resource` method, call super and do whatever you want with it, something like:

    def build_resource(*args)
      resource = super
      resource.company_id = 1 # for instance
      resource
    end

-- 
At.
Carlos Antonio

Bruce Ackerman

unread,
Feb 13, 2012, 12:24:13 AM2/13/12
to plataforma...@googlegroups.com
Hmm, so this is the best way to do an additional 
@company = Company.new(params[:name blah])
@company.save

to the devise controller?  

Carlos Antonio da Silva

unread,
Feb 13, 2012, 5:10:49 AM2/13/12
to plataforma...@googlegroups.com
Everything depends on what you want to achieve. For instance, ff you want to create a company together with the user, given user input, you should probably use nested attributes or something.

-- 
At.
Carlos Antonio

Bruce Ackerman

unread,
Feb 13, 2012, 9:41:02 AM2/13/12
to plataforma...@googlegroups.com
Hmm thanks


Thanks,
Bruce Ackerman 
Reply all
Reply to author
Forward
0 new messages