<分区>
我有两个 Rails 应用程序。我如何从本地应用程序删除远程应用程序上的 /public
中的文件?我意识到这个问题很模糊,只是不确定如何开始这一切?
谢谢!
<分区>
我有两个 Rails 应用程序。我如何从本地应用程序删除远程应用程序上的 /public
中的文件?我意识到这个问题很模糊,只是不确定如何开始这一切?
谢谢!
最佳答案
试试这个
在你的 Controller Action 中
if File.exist?(file_path)
File.delete(file_path)
end
首先你需要在你的 Rails 应用中允许 CORS 请求
在您的 application_controller.rb 中添加以下行
#application_controller.rb
class ApplicationController < ActionController::Base
before_filter :allow_cors_requests
def allow_cors_requests
headers["Access-Control-Allow-Origin"] = "*"
headers["Access-Control-Allow-Methods"] = "GET, PUT, POST, DELETE" # In your case just use delete
headers["Access-Control-Allow-Headers"] = "Content-Type, X-Requested-With, X-CSRF-Token, Origin Accept"
head(:ok) if request.request_method == "OPTIONS"
end
end
现在从您的 Controller 操作发出一个删除文件的 ajax 请求。
关于ruby-on-rails - rails : deleting a remote file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22185672/
相关文章:
ruby-on-rails - 将现有的 Rails 应用程序从 SQLite 迁移到 PostgreSQL
ruby-on-rails - Rails 3 Distinct 加入 Postgresql
html - 在网格中显示使用 PaperClip 上传的图像缩略图
ruby-on-rails - 在Rails ActiveRecord中分配给 boolean 字段时如何转换值?
ruby-on-rails - 这行代码是什么意思? !在 Hash [] 中
javascript - rails : Heroku assets in vendor getting 404
ruby-on-rails-3 - unicorn 挂着说刷新 gem