我有一个Rails应用程序,可以从手机上加载图片。该模型是钞票,并且有图片。
当我点击“提交”按钮以创建带有其图片的账单时,在生产中出现此错误:
2018-09-25T09:58:12.031850+00:00 heroku[router]: at=info method=POST path="/customers/3/bills" host=www.quickbill.club request_id=732a0100-094d-4555-a44b-1564fe43d1b8 fwd="45.56.153.44" dyno=web.1 connect=1ms service=22711ms status=500 bytes=1827 protocol=http
2018-09-25T09:58:12.015127+00:00 app[web.1]: I, [2018-09-25T09:58:12.014979 #4] INFO -- : [732a0100-094d-4555-a44b-1564fe43d1b8] Started POST "/customers/3/bills" for 45.56.153.44 at 2018-09-25 09:58:12 +0000
2018-09-25T09:58:12.019874+00:00 app[web.1]: I, [2018-09-25T09:58:12.019785 #4] INFO -- : [732a0100-094d-4555-a44b-1564fe43d1b8] Processing by BillsController#create as HTML
2018-09-25T09:58:12.020073+00:00 app[web.1]: I, [2018-09-25T09:58:12.020006 #4] INFO -- : [732a0100-094d-4555-a44b-1564fe43d1b8] Parameters: {"utf8"=>"✓", "authenticity_token"=>"j1ixxxxxxxxxxxx17l9Yw==", "bill"=>{"description"=>"Breakfast", "price"=>"0.0", "datum"=>"", "photo"=>#<ActionDispatch::Http::UploadedFile:0x000055fc25fe9968 @tempfile=#<Tempfile:/tmp/RackMultipart20180925-4-379snz.jpeg>, @original_filename="7483C9E3-618B-4B74-BFBF-6AF85E7F18E1.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"bill[photo]\"; filename=\"7483C9E3-618B-4B74-BFBF-6AF85E7F18E1.jpeg\"\r\nContent-Type: image/jpeg\r\n">}, "commit"=>"upload bill", "customer_id"=>"3"}
2018-09-25T09:58:12.031959+00:00 app[web.1]: I, [2018-09-25T09:58:12.031856 #4] INFO -- : [732a0100-094d-4555-a44b-1564fe43d1b8] Completed 500 Internal Server Error in 12ms
2018-09-25T09:58:12.032652+00:00 app[web.1]: F, [2018-09-25T09:58:12.032590 #4] FATAL -- : [732a0100-094d-4555-a44b-1564fe43d1b8]
2018-09-25T09:58:12.032744+00:00 app[web.1]: F, [2018-09-25T09:58:12.032678 #4] FATAL -- : [732a0100-094d-4555-a44b-1564fe43d1b8] RuntimeError ():
2018-09-25T09:58:12.032821+00:00 app[web.1]: F, [2018-09-25T09:58:12.032766 #4] FATAL -- : [732a0100-094d-4555-a44b-1564fe43d1b8]
2018-09-25T09:58:12.032914+00:00 app[web.1]: F, [2018-09-25T09:58:12.032861 #4] FATAL -- : [732a0100-094d-4555-a44b-1564fe43d1b8] app/controllers/bills_controller.rb:10:in `create'
保存帐单时,我试图挽救控制器中的错误:
def create
bill = Bill.new(bill_params)
customer_id = params[:customer_id]
@customer = Customer.find(customer_id)
bill.customer = @customer
bill.datum = Date.today if params[:bill][:datum].empty?
begin
bill.save
rescue RuntimeError => e
print_exception(e, true)
puts "albert errorrrr"
end
redirect_to customer_path(@customer)
end
但也不起作用。我检查了文档,我认为救援应该像这样编写。救援代码正确吗?还是我错过了什么?
预先感谢