I spent the last 3 days trying to solve an issue with my Rails app on DigitalOcean on production.
On my Mac running the app locally, the app executes API requests and handles them without problems. The logs and flashes are displayed whether the response is a 200 or another code. For example, if I update a PNG via a form but the API does only accept JPG, the app show the error in the flash and the logs work.
If I start the app on DigitalOcean and I send the correct request, I do not have any problem. But If, like before, I update a PNG I do not get displayed neither the flash nor the logs. I get only a redirection. Even the Log 1 which happens before the API call skin_analyze(@uploaded_file)
executes, is not diplayed. The Log 2 works on production always.
It seems like the code does not run, but it is not possible since it works if the response is successful.
This is the code without begin-rescue blocks and other stuff to simplify.
def upload
Rails.logger.debug "========= Log 1}"
if params[:file].blank?
Rails.logger.debug "========= Log 2}"
flash[:alert] = "Please upload a file before clicking Analyze."
return redirect_to skin_analyze_path
end
@uploaded_file = params[:file]
@response = skin_analyze(@uploaded_file)
if @response.code != 200
Rails.logger.debug "========= Log 3}"
json_response = JSON.parse(@response.body)
flash[:alert] = json_response["error_msg"] || json_response["message"]
redirect_to skin_analyze_path, data: { turbo: false }
end
...
end
The session contains always the same data, so this is not the problem. I also think it is not a flash problem because also the logs do not display.
This is the button that calls the function:
<%= form_with(url: picture_upload_path, method: :post, local: true, html: { multipart: true, id: 'uploadForm', class: 'mt-4' }) do |form| %>
<div class="col-12 mb-4">
<% is_disabled = @user.pictures.attached? && [email protected]_paying_customer? %>
<%= form.submit is_disabled ? "Upgrade to Pro for unlimited access" : "Analyze",
type: "submit",
class: "btn btn-primary w-100",
id: "analyze",
disabled: is_disabled,
data: { disable_with: "Analyzing..." } %>
</div>
<% end %>