Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 不能';找不到'';尝试添加到表中时id为的_Ruby On Rails_Activerecord - Fatal编程技术网

Ruby on rails 不能';找不到'';尝试添加到表中时id为的

Ruby on rails 不能';找不到'';尝试添加到表中时id为的,ruby-on-rails,activerecord,Ruby On Rails,Activerecord,我试图通过员工显示页面上的员工技能表表单向员工添加技能,但每次尝试创建时都会出现以下错误 错误: ActiveRecord::RecordNotFound in EmployeeSkillsController#create Couldn't find Employee with 'id'= 员工秀 <div class="section"> <div class="top-border left"></div> <div class="top-

我试图通过员工显示页面上的员工技能表表单向员工添加技能,但每次尝试创建时都会出现以下错误

错误:

ActiveRecord::RecordNotFound in EmployeeSkillsController#create

Couldn't find Employee with 'id'=
员工秀

<div class="section">
<div class="top-border left"></div>
  <div class="top-border right"></div>
    <h3> Add Skill</h3>
    <%= form_for([EmployeeSkill.new]) do |f| %>
    <%= @employee.name%>
<div class="field">
     <%= f.label :Skill %><br>
    <%= f.collection_select :skill_id, Skill.all, :id, :skillType, :prompt => "Select skill" %>
  </div>

  <div class="actions">
  <%= f.label:skillLevel%>
    <% stars = [1,2,3,4,5] %>
    <% stars.each do |star| %>
        <%= f.radio_button :skillLevel,star%> <%= star%>
    <%end%>
    </br>
    <%= button_to "Add Skill", employee_skills_path(employee_id: @employee.id), class: "btn btn-primary" %> 
    </form>
</div>
<%end%>
更新

日志文件

Started POST "/employee_skills" for ::1 at 2017-04-26 12:35:38 +0100
Processing by EmployeeSkillsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"bJ/wgo1Iz7KqLDtijEZ/emuWTuS4UblMlVnz7SyBZUSR7MJlxAmtXk5LS661t6598WfnCycDf6LtUHwhTOf9hQ==", "employee_skill"=>{"skill_id"=>"1", "skillLevel"=>"3"}}
  [1m[35mEmployee Load (0.5ms)[0m  SELECT  "employees".* FROM "employees" WHERE "employees"."id" = ? LIMIT 1  [["id", 1]]
  [1m[36mEmployee Load (1.0ms)[0m  [1mSELECT  "employees".* FROM "employees" WHERE "employees"."id" = ? LIMIT 1[0m  [["id", nil]]
Completed 404 Not Found in 22ms (ActiveRecord: 1.5ms)

ActiveRecord::RecordNotFound (Couldn't find Employee with 'id'=):
  app/controllers/employee_skills_controller.rb:31:in `create'


  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (1.5ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (12.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (5.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (292.9ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (2.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (1.5ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (2.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (1.5ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (485.7ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (1.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (3.0ms)
  Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (885.4ms)

show
操作中初始化
EmployeeSkill
的实例

@employee = Employee.find(params[:id]) 
@employee_skill = @employee.employee_skills.new
# The above statement will set :employee_id with employee's id
然后在表单中使用它

<%= form_for([@employee, @employee_skill]) do |f| %>

发布从日志发送到创建操作的参数。将日志添加到问题
params[:employee_id]
中的参数不在其中,这就是为什么会发生这种情况。您的意思是什么?我正在尝试从用户所在的显示页面获取员工id。您没有在参数中提交员工id。你唯一的参数是“employee_skill”=>{“skill_id”=>“1”,“skillLevel”=>“3”}刚刚开始尝试这个,现在得到了一个“未定义的方法`employee_employee_skills_path` for#”错误,这是我对路线的猜测。您应该检查路径是否正确,或者是否尝试运行
rake routes
,并使用适当的urlnew_employee_skill_path GET/employee_skills/new(:format)employee_skills#new我将rul更改为new_employee_path,现在正在获取“没有路线匹配[张贴]”/employee\u skills/new.1“”,不确定为什么这不起作用?我知道这是一个问题,但为什么?
<%= form_for([@employee, @employee_skill]) do |f| %>
<%= form_for([@employee, @employee_skill], url: employee_employee_skills_path(@employee)) do |f| %>