【问题标题】:How to add new profile for a particular user?如何为特定用户添加新配置文件?
【发布时间】:2013-08-29 07:01:36
【问题描述】:

我有一个用户模型和一个配置文件模型。在user.rb中

has_one :profile

在配置文件模型中

belongs_to :user

现在我尝试在profiles#create中为当前用户创建个人资料

@profile = current_user.profile.new(params[:profile])

它会引发未知方法“新”错误。 如何解决这个问题?请帮忙?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 associations


    【解决方案1】:

    @profile = current_user.build_profile(params[:profile])
    @profile.save!

    【讨论】:

      猜你喜欢
      • 2021-12-28
      • 2012-09-20
      • 2012-02-04
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多