Devise controllers rails

前端 未结 2 1927
醉酒成梦
醉酒成梦 2021-02-06 16:39

I\'m using Rails 3, on ruby 1.8.7. And using for auth. devise (1.1.3). But it is a quite large community site i\'m building, so i have a table for profiles and a table for users

2条回答
  •  無奈伤痛
    2021-02-06 17:18

    There's not really any need to involve the controller in this; models can (and should) do all of the heavy lifting here.

    I'm assuming that you have a relationship between User and Profile models, in which case, you should just be able to do something like this:

    class User < ActiveRecord::Base
      has_one :profile # could be a belongs_to, but has_one makes more sense
    
      after_create :create_user_profile
    
      def create_user_profile
        create_profile(:column => 'value', ...)
      end
    end
    

提交回复
热议问题