I've got two Rails apps. How would I delete a file in /public
on the remote app from the local app? Pretty vague question I realise, just not sure how to start it all?
Thanks!
I've got two Rails apps. How would I delete a file in /public
on the remote app from the local app? Pretty vague question I realise, just not sure how to start it all?
Thanks!
Try this
In your controller action
if File.exist?(file_path)
File.delete(file_path)
end
First you need to allow CORS Requests in your Rails app
In your application_controller.rb add the following lines
#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
Now from your controller action make a ajax request to delete a file.