Home > Mobile >  ActiveRecord::RecordNotFound in WorkersController#create ,Couldn't find Company with 'id&#
ActiveRecord::RecordNotFound in WorkersController#create ,Couldn't find Company with 'id&#

Time:09-21

i want to create a worker with the company_id. Now i need to place the company_id into the view but i get this error(ActiveRecord::RecordNotFound (Couldn't find Company with 'id'=):), can anyone help me to see where did i do wrong?Thanks

worker controller(part 1)

worker controller(part2)

views/new.html.erb(where the form is

Error page

CodePudding user response:

Try to add value to ..."company_id"=>"**ID_YOU_ARE_SEARCHING_FOR**"...

It should be set on the call to your create method

CodePudding user response:

In your Form views/new.html.erb, you're passing company_id as hidden_field but value has not been passed there, which is the reason for the error(company_id's value not present)

<%= f.hidden_field :company_id %>

Below line would fix it, you need to pass value in your form like shown below. This would pass 1 as company_id, but you need to change it based upon how and from where you're getting this value.

<%= f.hidden_field :company_id, value: 1 %>
  • Related