Ruby on rails Rails中设计用户的配置文件模型

Ruby on rails Rails中设计用户的配置文件模型,ruby-on-rails,ruby,devise,Ruby On Rails,Ruby,Devise,我正试图为Desive用户创建一个单独的配置文件模型,比如位置、传记等等。问题是我无法将其保存到数据库中 我的用户被称为“艺术家” ####/routes.rb### 获取'artists/:id/new_profile'=>'artists/profiles#new',as::profile 发布“艺术家/:id/new_profile”=>“艺术家/个人资料#创建” ###艺术家/配置文件\u controller.rb### 类艺术家::ProfilesController

我正试图为Desive用户创建一个单独的配置文件模型,比如位置、传记等等。问题是我无法将其保存到数据库中

我的用户被称为“艺术家”

####/routes.rb###
获取'artists/:id/new_profile'=>'artists/profiles#new',as::profile
发布“艺术家/:id/new_profile”=>“艺术家/个人资料#创建”
###艺术家/配置文件\u controller.rb###
类艺术家::ProfilesController

我在这里做错了什么?

在尝试保存之前,请确保为配置文件设置了艺术家id

@profile = ArtistProfile.new(profile_params, artist_id: @artist.id)


应该可以工作。

您需要使用
当前艺术家
对象初始化配置文件

class Artists::ProfilesController < ApplicationController
  before_action :authenticate_artist!

  def new
    @artist = current_artist
    @profile = @artist.build_profile
  end

  def create
    @artist = current_artist
    @profile = @artist.build_profile(profile_params)
    if @profile.save
      redirect_to current_artist
    else
      render 'new'
    end
  end
end
类艺术家::ProfilesController
更新:

要使用此示例,您的关联应该如下

class Artist < ActiveRecord::Base
  has_one :profile, class_name: ArtistProfile
end
class-Artist
在控制器中,您缺少配置文件参数方法

private 

def profile_params
        params.require(:profile).permit(:biography, :location)
end
class Artist < ActiveRecord::Base
  has_one :profile, class_name: ArtistProfile
end
private 

def profile_params
        params.require(:profile).permit(:biography, :location)
end