I am working with has_many :through association in Application. I implement association between models like :-
in employee.rb
class Employee < ActiveRecord::Base
has_many :inventories, through: :employee_inventories
end
in inventory.rb
class Inventory < ActiveRecord::Base
has_many :employees, through: :employee_inventories
end
in employee_inventories.rb
class EmployeeInventory < ActiveRecord::Base
belongs_to :employee
belongs_to :inventory
end
I create a method in InventoryController.rb like:
def inventory_status
p 'paramsssssssssssssssssssssssssssss'
p params
p employee_inventories_params
@employee_inventories = @inventory.employee_inventories.build(employee_inventories_params)
if @employee_inventories.save
p 'sssssssssssssssssssssssssss'
redirect_to inventories_path
else
p 'aaaaaaaaaaaaaaaaa'
render :action => :show
end
def employee_inventories_params
params.require(:employee_inventory).permit(:employee_id, :status)
end
and in view of my application I render this method by this
<%= link_to 'Request for inventory', inventory_status_inventory_path(@inventory),
:class => 'btn btn-success' %>
when I run this this gives me error
ActionController::ParameterMissing (param is missing or the value is empty: employee_inventory)
I want to store employee_id and status in employee_inventory table. please guide me. How to implement? Thankz in advance.
Please try this code
and in your view
hope this will help you.