1
我的問題:用戶has_one配置文件。當新用戶創建時,APP也會自動創建屬於用戶的配置文件。我試圖通過控制器,通過回調,總是相同的錯誤(堆棧層太深)。我的模型:堆棧級別太深:創建子級記錄
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 this 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])
@[email protected]
if @user.save
session[:user_id] = @user.id
@[email protected]_profile
redirect_to root_url, notice: "Thank you for signing up!"
else
render "new"
end
end
Alsways同樣的錯誤。爲什麼?
爲什麼endessly? user create =在創建回調=> user.build_profile之後創建。我希望每個用戶都有配置文件,所以當用戶創建時,應用程序也應該創建相關的配置文件 –
看到我的編輯上面 – apneadiving
謝謝)似乎我對自我工作如何不完成 –