ruby on rails - Stack level too deep: creating child-record -
my problem: user has_one profile. when new user created, app automatically creates profile, belongs user. tried through controller, through callback, same error (stack level deep). models:
class user < activerecord::base has_secure_password attr_accessible :email, :password, :password_confirmation validates_uniqueness_of :email, :case_sensitive => false validates :email, :email_format => true validates :password, :length=> {:in=> 5...32} validates :email, :password, :password_confirmation, :presence =>true has_many :authentications has_many :tests has_many :answers has_many :results has_one :profile #after_create :build_profile #tried way def build_profile self.build_profile end end
#
class profile < activerecord::base attr_accessible :user_id belongs_to :user end
#
def create @user = user.new(params[:user]) @user.email=@user.email.downcase if @user.save session[:user_id] = @user.id @profile=@user.build_profile redirect_to root_url, notice: "thank signing up!" else render "new" end end
alsways same error. why?
def build_profile self.build_profile end
this loops endlessly (and can't see point, did want do?)
you should remove build_profile
method (don't worry, it's defined association).
user = user.new user.build_profile |_ calls self.build_profile, self user |_ calls user.build_profile |_ ...
Comments
Post a Comment