0
私は、S3でPaperclipを使用してファイルを保存していますが、ユーザーがアプリケーションから入力した画像を保存していますが、 、ここで問題を説明するための私のコードは次のとおりです。ActiveRecord specific selectはpaperclip urlを持っていません
私がデータベース(file_nameに、FILE_SIZE、file_updated_at、file_content_typeにファイルを格納すべてのフィールドを選択する必要があるように思わペーパークリップのURLジェネレータを見てみるとclass UploadedFile < ActiveRecord::Base
has_attached_file :file
attr_accessor :file_url
def file_url
self.file.url(:original) if self.file
end
end
UploadedFile.first.as_json(methods: [:file_url]) #Will work and will show the url in the json
UploadedFile.all.as_json(methods: [:file_url]) #Will work and will show the url in the json
UploadedFile.select('id', 'othertablecolumn').joins("JOINS SOMETING").where("SOME CONDITIONS").as_json(methods: [:file_url]) #Will not work and will show the missing url in the json