我有通过设计的用户,并通过脚手架创建了个人资料,现在一切都很好,但我不能“连接”用户的个人资料。
这是我到目前为止所做的-
user.rb
has_one :profileprofile.rb
belongs_to :user我也通过迁移在profiles表中创建了user_id列。
现在,当我登录并填写表单/profiles/new时,它会创建配置文件,但无法链接到用户,因为user_id字段为空。此外,用户能够创建多个配置文件,因为我认为他只能创建一个,因为我已经把:has_one关系?
有什么帮助吗?
编辑-在profiles_controller文件中,我也尝试更改
@user_profile = UserProfile.new(params[:user_profile])至
@user_profile = current_user.userprofile.new(params[:user_profile])但它提供了未定义的方法“UserProfile”
发布于 2012-12-29 20:45:57
@user_profile = current_user.userprofile.new(params[:user_profile])应该是
@user_profile = current_user.build_user_profile(params[:user_profile])https://stackoverflow.com/questions/14081788
复制相似问题