1

I use Rails 3.0.3 and devise 1.1.5 (devise on github)

My User model belongs_to the Company model with the foreign_key company_id

When a new User is created (at Sign Up), I need to associate him with a new company.

So, basically, I need to put the following code somewhere

@user.company = Company.new
@user.save

The user controller is manage in the devise dependency, is it possible to generate the controller used by devise in my app/controllers directory

Thanks

denisjacquemin
  • 7,414
  • 10
  • 55
  • 72

2 Answers2

1

You can customize devise controllers - just copy the default ones from devise/app/controllers into your own application directory and add your own code to them.

eugen
  • 8,916
  • 11
  • 57
  • 65
  • See also http://stackoverflow.com/questions/3546289/override-devise-registrations-controller – eugen Feb 05 '11 at 14:40
  • in a rails 3 project... where is the devise/app/controllers directory? – jpw Feb 21 '11 at 05:18
  • jpqynn, Had the same question. If you are using RVM, it would be in ~/.rvm/gems/ruby-1.9.3-p194@gemset_name/gems/devise-2.1.0/app/controllers/ – Flaviu Jun 08 '12 at 03:03
1

Because a company has to be associated for each new user, I put this code in the User model in a before_create filter.

denisjacquemin
  • 7,414
  • 10
  • 55
  • 72