How to create another object when creating a Devise User from their registration form in Rails?

后端 未结 2 1436
我在风中等你
我在风中等你 2021-02-10 18:38

There are different kinds of users in my system. One kind is, let\'s say, a designer:

class Designer < ActiveRecord::Base
  attr_accessible :user_id, :portfol         


        
2条回答
  •  别跟我提以往
    2021-02-10 19:16

    If you don't want to change the registration controller, one way is to use the ActiveRecord callbacks

    class User < ActiveRecord::Base
      after_create :create_designer
    
      private
    
      def create_designer
          Designer.create(user_id: self.id) 
      end
    end
    

提交回复
热议问题