Ruby on rails 4 载波不会从存储器中删除文件
我有两种型号Ruby on rails 4 载波不会从存储器中删除文件,ruby-on-rails-4,carrierwave,Ruby On Rails 4,Carrierwave,我有两种型号用户和附件,其中用户有许多附件和附件属于用户 我正在尝试使用Carrierwave实现文件上传/下载服务 以下是我保存上传的方式: def create uploader = LauncherUploader.new @user = User.find(params[:user_id]) @attachment = Attachment.new(params[:attachment => {:file => [ :original_filename
用户
和附件
,其中用户有许多附件
和附件属于用户
我正在尝试使用Carrierwave实现文件上传/下载服务
以下是我保存上传的方式:
def create
uploader = LauncherUploader.new
@user = User.find(params[:user_id])
@attachment = Attachment.new(params[:attachment => {:file => [ :original_filename ]}])
@attachment.name = params[:attachment][:file].original_filename
@attachment.format = params[:attachment][:file].content_type
@attachment.user_id = @user.id
@attachment.save
uploader.store!(params[:attachment][:file])
redirect_to user_attachments_path, notice: "The file #{@attachment.name} was uploaded"
end
这就是我试图删除文件的方式:
def destroy
@user = User.find(params[:user_id]) or not_found
@attachment = @user.attachments.find(params[:id])
@attachment.destroy
uploader = LauncherUploader.new
uploader.remove_attachment!(@attachment)
redirect_to user_attachments_path, notice: "The file #{@attachment.name} has been deleted."
end
我的上传程序叫做启动器
。当前的destroy
方法从数据库中删除记录,但不从内存中删除。需要采取什么措施来纠正这种行为
编辑
这是当前附件的显示方式
[查看]
<% @attachments.each do |attachment| %>
<tr>
<td><%= attachment.name %></td>
<td><%= attachment.format %></td>
<td><%= link_to 'Download Link', :action => 'download' , :id => attachment.id %></td>
<td><%= button_to 'Delete', user_attachment_path(params[:user_id], attachment),
method: :delete,
data: { confirm: 'Are you sure?' }, :class => 'btn' %></td>
</tr>
<% end %>
此列表中不显示任何已删除的文件。但是仍然存在于上传的文件夹中。为什么说内存?你的意思是当页面加载时,你可以在浏览器中看到它吗?你能把你显示图像的代码放进去吗?@MrH否。我的意思是它没有列出页面加载时的文件。但该文件存在于上载该文件的文件夹中。没有数据库条目,但上载文件夹中仍存在文件。请再次运行应用程序,然后检查日志并将其放在此处。谢谢上传文件夹没有权限问题是吗?
def index
@attachments = Attachment.where(:user_id => params[:user_id])
end