我有一个私有和第三方检查。在自动创建私有检查记录后,我需要创建第三方检查。因此,我必须使用不同的参数再次从控制器调用create_history方法
class HomesController < BaseController
def create_history
#<ActionController::Parameters {"request_type"=>"Private", "user_id"=>"25" "requested_at"=>"Oct 28, 2022","private_inspection_type_id"=>"23780"} permitted: true>
inspection_request = @home.inspection_requests.new(inspection_request_history_params)
inspection_request.save
if inspection_request.get_paired_inspection.present?
inspection_request_history_params = {request_type: "Third Party", third_party_inspection_id: inspection_request.get_paired_inspection.id, status: inspection_request.status, user_id: inspection_request.user_id, requested_at: inspection_request.requested_at }
create_history
end
end
def inspection_request_history_params
params.require(:inspection_request).permit(:request_type, :user_id, :requested_at, :performed_at, :private_inspection_type_id, :third_party_inspection_id)
end
当我尝试通过传递不同的参数来调用create_history方法时,我没有得到参数。
1条答案
按热度按时间c9qzyr3d1#
我觉得把
inspection_request.save
放在不同的方法上比较好