When you want to check if a file is attached to your model, the official Carrierwave documentation says:
u.avatarwill never return nil, even if there is no photo associated to it. To check if a photo was saved to the model, use
That's fine, it works. BUT! If you are using a cloud storage service like Amazon S3, each time the line
file.nil? will be executed, a request will be sent to the cloud storage to check the presence of the file. As you guess, it's not cool because it can make your app slower.
The solution is simply to use
u.avatar.present?. This way, no more external call.