2
如何读取carrierwave上传器中的当前用户?从本质上讲,在WhateverUploader.rb我有 -Rails,carrierwave,并将用户名添加到文件名
def store_path(for_file = filename)
"uploads/#{Rails.env}/#{model.class.to_s.underscore.pluralize}/#{mounted_as}/#{model.id}/#{for_file}"
end
...我想放像
.../#{current_user.username}/...
我使用的设计,而是CURRENT_USER似乎并不可用在上传者。是否合理做类似
.../#{User.find(Book.find(Chapter.find(model.id).book_id).user_id).username}/...
还是我坚果?它工作正常,但似乎不是最佳的。