对于某个员工,我有一份报告。每个报告都有一些变化。每个班次都可以纠正。我正在从 Ruby 2 迁移到 Ruby 3。我正在处理部分页面。当我点击正确时,会出现一个部分页面,当我点击更新时,页面应该返回到带有该员工 ID 的部分页面详细信息。
_modify_item.html.erb:
<%= form_for :modified_item, :url => {:action => :modify_item, :report_id => @monthly_report.id, :modified_item_id => @modified_item.id,remote: true} do |form| %>
<table width=100% height=100%>
<td width=150 style='border: 0px; background-color: #eee' align=center>
<%= form.hidden_field :report_id, :value => @monthly_report.id %>
<%= submit_tag 'Update', :name => 'update', :value => 'Update', :class => 'highlighted_button' %>
<%= link_to 'Cancel',
{:action => 'details', :report_id => @monthly_report.id},
:class => 'highlighted_button',
remote: true %>
</td>
</tr>
</table>
<% end %>
控制器.rb:
def modify_item
@modified_item = Employee::MonthlyReportItem.find(params[:modified_item_id])
@monthly_report = @modified_item.report
begin
@modified_item.update_attributes!(params[:modified_item])
flash[:notice] = 'Position was updated.'
flash[:warning]=@modified_item.verification_problems if !@modified_item.correct?
redirect_to('/accounts/salary/details', :report_id => @monthly_report.id) and return
rescue Exception => e
flash.now[:error] = "Some of the values are missing or are incorrect. Try again."
end
#render(:partial => 'details') and return
end
modify_item.js.erb:(试过没有成功)
//$("#salary_popup").html("<%= j(render partial: 'details') %>");
更新:忘了提到 if 内部的确切错误
Couldn't find Employee::MonthlyReport without an ID
Rails 进入 details 函数并尝试这样做:
def details
if params[:item].nil?
@monthly_report = Employee::MonthlyReport.find(params[:report_id])
else
@monthly_report = Employee::MonthlyReport.find(params[:item][:report_id])
end
..
end