I recently ran into this following code in a project that I inherited:
def get_company_doc_file(company_doc)
if Rails.env.development?
company_doc.company_file.path
else
company_doc.company_file.url
end
end
The problem with this code is that if I want to troubleshoot the remote files on production or staging in a local development version of the application, I will get some strange errors and worse: I won’t know what is causing my errors!
Here’s the correct way to handle this:
def get_company_doc_file(company_doc)
if company_doc.company_file.options[:storage] == :filesystem
company_doc.company_file.path
else
company_doc.company_file.url
end
end
In general, I recommend people stay away from using Rails.env.development?
anywhere in the app
or lib
folder of the Rails code.