Ruby on rails 控制器问题中的实例变量定义:Rails 5

Ruby on rails 控制器问题中的实例变量定义:Rails 5,ruby-on-rails,instance-variables,Ruby On Rails,Instance Variables,我有一个单用户表,其中有两个使用enum定义的角色,还有一个单表继承,其中有两个匹配的用户子类,用于员工和临床医生。因为我需要很多关于临床医生的信息,而不需要关于员工的信息,所以我创建了一个临床医生配置文件表,并在用户模型中使用after_create:create_clinican_profile为临床医生配置文件创建存根 我正在尝试为临床医生创建一个页面来完成他们的配置文件,但在获取控制器中定义的实例变量时遇到了问题,因此它会将相应临床医生的配置文件拉入视图以呈现表单。我得到以下错误。请注意

我有一个单用户表,其中有两个使用enum定义的角色,还有一个单表继承,其中有两个匹配的用户子类,用于员工和临床医生。因为我需要很多关于临床医生的信息,而不需要关于员工的信息,所以我创建了一个临床医生配置文件表,并在用户模型中使用after_create:create_clinican_profile为临床医生配置文件创建存根

我正在尝试为临床医生创建一个页面来完成他们的配置文件,但在获取控制器中定义的实例变量时遇到了问题,因此它会将相应临床医生的配置文件拉入视图以呈现表单。我得到以下错误。请注意,我登录的用户id是104

ActiveRecord::RecordNotFound in ClinicianProfilesController#edit
Couldn't find ClinicianProfile with 'id'=104
我觉得我很接近,但不知道我做错了什么。对于新手,任何帮助都将不胜感激

我使用标题中的此链接登录页面:

<li><%= link_to "Manage My Profile", edit_clinician_profile_path(current_user) %></li>
临床医生档案管理员

class ClinicianProfilesController < ApplicationController
def edit
    @clinician_profile = ClinicianProfile.find(params[:id])
end

def index
end

def show
end

def create
end

end
class ClinicianProfilesController
以下是我的视图的开始(在/views/clinician\u profiles中编辑.html.erb)



您似乎没有创建id为104的临床医生档案。检查您是否传递了正确的参数[:id]是的,您的用户id不是104吗?(与您一起登录的)。属于该用户的临床医生配置文件可能具有不同的id。您可能会得到如下信息:
@clinician\u profile=当前用户。如果您知道是“临床医生”,如何登录到编辑视图?通过点击链接?如果是这样的话,发布代码。在某个地方您传递了错误的
params
感谢您的回复!Pavan我刚刚在我的原始帖子中添加了代码链接。rccursach的解决方案奏效了。这是有道理的,而且现在你已经指出了这一点,这似乎是完全显而易见的。我发誓我会到达那里。。。谢谢你们想说什么?检查@clinician_profile是否为空,然后返回索引页,不编辑表单。
class ClinicianProfile < ApplicationRecord
    has_many :clinician_profile_languages
    has_many :languages, through: :clinician_profile_languages
    has_many :clinician_profile_races
    has_many :races, through: :clinician_profile_races
    belongs_to :clinician
end
create_table "clinician_profiles", force: :cascade do |t|
    t.datetime "created_at",          null: false
    t.datetime "updated_at",          null: false
    t.string   "firstname"
    t.string   "lastname"
    t.string   "address1"
    t.string   "address2"
    t.string   "city"
    t.string   "state"
    t.string   "zip"
    t.boolean  "accepting_patients"
    t.integer  "rate"
    t.string   "license_number"
    t.string   "license_state"
    t.string   "school"
    t.integer  "year_graduated"
    t.string   "accepts_insurance"
    t.boolean  "sliding_scale"
    t.text     "bio"
    t.boolean  "verified"
    t.integer  "years_licensed"
    t.integer  "years_of_experience"
    t.integer  "clinician_id"
  end
class ClinicianProfilesController < ApplicationController
def edit
    @clinician_profile = ClinicianProfile.find(params[:id])
end

def index
end

def show
end

def create
end

end
<%= form_for(@clinician_profile) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
def edit
    @clinician_profile = ClinicianProfile.find(params[:id])
    redirect_to :index and return unless @clinician_profile
end