I have two models Employee and Overtime Definition The Associations are set like this
Employee
class Employee < ActiveRecord
Your current edit link is:
<%= link_to "Re-Calculate",:action => "edit",:id=>employee.id,:flag=>"Re-Calculate" %>
In your edit action:
@overtime = OvertimeDefinition.find(params[:id][:employee_id]) ## gives me can't convert Symbol into Integer error.
As per the edit link, you are directly passing :id in query params which you can access as params[:id]. There is no params[:id][:employee_id] in your params hash so when you say params[:id][:employee_id] Ruby tries to convert :employee_id to an integer which is a symbol. Hence, the error.
I think you should be passing id of OvertimeDefinition record in :id from your link. And access it as
@overtime = OvertimeDefinition.find(params[:id])
in the Controller's action.
@overtime = OvertimeDefinition.find(params[:id]) ## gives me Couldn't find OvertimeDefinition with ID=1353 error.Actually 1353 is the id of that employee.
This is because you are passing employee id in params[:id] so obviously this will not work. You need to pass OvertimeDefinition id here.
@overtime = OvertimeDefinition.find(params[:employee_id]) ## gives me couldn't find OvertimeDefinition without an ID error.
You are not passing any :employee_id in query params within edit link. So, params[:employee_id] will be nil and find method fails because you didn't pass any id to it.
Update your edit link as below:
<%= link_to "Re-Calculate",:action => "edit",:id=> @overtimedefinition.id , :employee_id => employee.id,:flag=>"Re-Calculate" %>
Replace @overtimedefinition.id with appropriate id of OvertimeDefinition record. As you have not shared the code, I don't know the name of OvertimeDefinition variable.
Update your edit action as:
def edit
@flag = params[:flag]
@overtime = OvertimeDefinition.find(params[:id])
@employee = Employee.find(params[:employee_id])
end