두 가지 모델이 Employee
있고 Overtime Definition
The Associations는 이렇게 설정되어 있습니다.
종업원
class Employee < ActiveRecord::Base
has_many :overtime_definitions
초과 근무 정의
class OvertimeDefinition < ActiveRecord::Base
belongs_to :employee
직원에 대한 초과 근무 정의를 작성했는데 모두 괜찮아 보이지만 직원에 대해 동일한 내용을 편집하는 데 어려움이 있습니다.
overtime_definitions__controller :
def new
@flag = params[:flag]
@employee = Employee.find(params[:id])
@overtime = OvertimeDefinition.new
end
def create
@employee = Employee.find(params[:overtime_definition][:employee_id])
@overtime = OvertimeDefinition.new(params[:overtime_definition])
if (params[:half_day_extra_duty_hours][:hour].to_s !="" || params[:half_day_extra_duty_hours][:minute].to_s !="")
@overtime.half_day_extra_duty_hours = params[:half_day_extra_duty_hours][:hour].to_s + ":" + params[:half_day_extra_duty_hours][:minute].to_s + ":" + "00"
else
@overtime.half_day_extra_duty_hours = nil
end
if (params[:full_day_extra_duty_hours][:hour].to_s !="" || params[:full_day_extra_duty_hours][:minute].to_s !="")
@overtime.full_day_extra_duty_hours = params[:full_day_extra_duty_hours][:hour].to_s + ":" + params[:full_day_extra_duty_hours][:minute].to_s + ":" + "00"
else
@overtime.full_day_extra_duty_hours = nil
end
if @overtime.save
flash[:notice] = "Overtime Successfully Created for #{@employee.name}"
redirect_to :action => 'search_overtime'
end
end
def edit
@flag = params[:flag]
@overtime = OvertimeDefinition.find(params[:id][:employee_id])
@employee = Employee.find(params[:id])
end
def update
@employee = Employee.find(params[:id])
@overtime = OvertimeDefinition.find(params[:id])
if @overtime.update_attributes(params[:overtime_definition])
flash[:notice] = "Overtime Successfully Updated for #{@employee.name}"
redirect_to :action => 'search_overtime'
else
render :action => 'edit',:flag=>params[:flag]
end
end
이것들을 편집 방법으로 시도했습니다.
@overtime = OvertimeDefinition.find(params[:id][:employee_id])
# can't convert Symbol into Integer
오류가 발생합니다.
@overtime = OvertimeDefinition.find(params[:id])
#gives me Couldn't find OvertimeDefinition with ID=1353
error. 실제로 1353은 해당 직원의 ID입니다.
삼.@overtime = OvertimeDefinition.find(params[:employee_id])
# couldn't find OvertimeDefinition without an ID
오류가 발생합니다.
신규 및 수정 작업에 대한 링크가있는 내 _search_overtime_employee_list
<%=link_to "Calculation" ,:action => "new",:id=>employee.id, :flag=>"Calculation" %>
<%= link_to "Re-Calculate",:action => "edit",:id=>employee.id,:flag=>"Re-Calculate" %>
new.rhtml
<%= form_tag :action => 'create' do %>
<%= render :partial =>'form'%>
<center>
<%= submit_tag "Save",:onclick=>"return validate()",:class=>"buttons"%>
</center>
<% end %>
<%= link_to "Back" ,:action => "search_overtime" %>
edit.rhtml
<%= form_tag :action => 'update', :id=>@employee.id,:flag=> params[:flag],:value=>params[:id] %>
<%= render :partial =>'form'%>
<center>
<%= submit_tag "Update",:onclick=>"return validate()",:class=>"buttons"%>
</center>
<%= link_to "Back" ,:action => "search_overtime" %>
_form.rhtml
직원 세부 정보
<table cellspacing="5">
<tr>
<td><b>Employee Code</b></td>
<%= hidden_field 'overtime_definition','employee_id',:value=>params[:id] %>
<td><%= @employee.employeeid %></td>
<td><b>Employee Name</b></td>
<td><%= @employee.personnel.display_full_name %></td>
</tr>
<tr>
<td><b>Department</b></td>
<td><%= @employee.department ? @employee.department.name : "" %></td>
<td><b>Designation</b></td>
<td><%= @employee.designation ? @employee.designation.name : "" %></td>
<td><b>Location</b></td>
<td><%= @employee.location.name%></td>
</tr>
</table>
</br>
<fieldset>
<table cellspacing="5">
<%= form_for :overtime_definition, :builder => LabelFormBuilder do |od| %>
<tr>
<td>
<label for="half_day_extra_duty_hours">
Half Day Extra Duty Hours
</label>
</td>
<td class ="datefamily">
<%= select_time(@overtime.half_day_extra_duty_hours, {:include_blank => true, :time_separator => ":",:prefix => "half_day_extra_duty_hours"})%>
</td>
</tr>
<tr>
<td>
<label for="full_day_extra_duty_hours">
Full Day Extra Duty Hours
</label>
</td>
<td class ="datefamily">
<%= select_time(@overtime.full_day_extra_duty_hours, {:include_blank => true, :time_separator => ":",:prefix => "full_day_extra_duty_hours"})%>
</td>
</tr>
<tr>
<%= od.sr_check_box :is_salary_basis, {}, true, false, :label => "Is Salary Basis"%>
</tr>
<tr>
<%= od.sr_check_box :is_fixed_amount, {}, true, false, :label => "Is Fixed Amount"%>
<td colspan="2" id="ov_hm" style="display: none">
Half Day Amount
<%= od.text_field :half_day_amount, :onkeypress => "return numbersonly(event)", :style => "width:40px" %>
</td>
<td colspan="2" id="ov_fm" style="display: none">
Full Day Amount
<%= od.text_field :full_day_amount, :onkeypress => "return numbersonly(event)", :style => "width:40px" %>
</td>
</tr>
<%end%>
</table>
편집 작업을하는 데 완전히 빠져 들었습니다. 어떤 도움이라도 대단히 감사합니다!
현재 edit
링크 :
<%= link_to "Re-Calculate",:action => "edit",:id=>employee.id,:flag=>"Re-Calculate" %>
편집 작업에서 :
@overtime = OvertimeDefinition.find (params [: id] [: employee_id]) ##는 Symbol을 Integer 오류로 변환 할 수 없습니다.
편집 링크에 따라 :id
액세스 할 수있는 쿼리 매개 변수를 params[:id]
. 더 없습니다 params[:id][:employee_id]
당신이 말할 때 귀하의 PARAMS 해시에 params[:id][:employee_id]
루비 변환을 시도 :employee_id
상징 정수로. 따라서 오류입니다.
:id
링크에서 OvertimeDefinition 레코드의 ID를 전달해야한다고 생각합니다 . 다음으로 액세스
@overtime = OvertimeDefinition.find(params[:id])
컨트롤러의 행동에서.
@overtime = OvertimeDefinition.find (params [: id]) ## ID = 1353 오류로 OvertimeDefinition을 찾을 수 없습니다. 실제로 1353이 해당 직원의 ID입니다.
이것은 당신이 통과 employee id
하고 params[:id]
있기 때문에 분명히 이것은 작동하지 않을 것입니다. 여기에 OvertimeDefinition ID를 전달해야합니다.
@overtime = OvertimeDefinition.find (params [: employee_id]) ## ID 오류없이 OvertimeDefinition을 찾을 수 없습니다.
링크 :employee_id
내에서 쿼리 매개 변수를 전달하지 않습니다 edit
. 따라서 params [: employee_id]는 nil이되고 find
ID를 전달하지 않았기 때문에 메서드가 실패합니다.
다음 edit link
과 같이 업데이트하십시오 .
<%= link_to "Re-Calculate",:action => "edit",:id=> @overtimedefinition.id , :employee_id => employee.id,:flag=>"Re-Calculate" %>
@overtimedefinition.id
OvertimeDefinition 레코드의 적절한 ID로 바꿉니다 . 코드를 공유하지 않았으므로 OvertimeDefinition 변수의 이름을 모릅니다.
edit
작업을 다음과 같이 업데이트하십시오 .
def edit
@flag = params[:flag]
@overtime = OvertimeDefinition.find(params[:id])
@employee = Employee.find(params[:employee_id])
end
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다