従業員の表示ページのemployee_skillテーブルフォームを使用して従業員にスキルを追加しようとしていますが、それを作成する。テーブルに追加しようとしたときに '' with id =が見つかりません
エラー:
ActiveRecord::RecordNotFound in EmployeeSkillsController#create
Couldn't find Employee with 'id'=
従業ショー
従業員のスキルコントローラ
# POST /employee_skills
# POST /employee_skills.json
def create
@employee_skill = EmployeeSkill.new
@employee = Employee.find(params[:employee_id])
@employee_skill.employee_id= @employee.id
respond_to do |format|
if @employee_skill.save
#session[:employee_id] = nil
format.html { redirect_to @employee, notice: 'Employee skill was successfully created.' }
format.json { render :show, status: :created, location: @employee_skill }
else
format.html { render :new }
format.json { render json: @employee_skill.errors, status: :unprocessable_entity }
end
end
end
UPDATE
ログファイル
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)
ログから作成アクションに送信されるパラメータを送信します。 – bkunzi01
質問に追加されたログ – David16
'params [:employee_id]'はパラメータにはありません。そのため、これが起こります。 – Iceman