ある従業員について報告があります。各レポートにはいくつかのシフトがあります。各シフトは修正できます。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は詳細機能に入り、これを試します:
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