के माध्यम से कुछ भी अनुमति दें मैं कोर को कैसे अक्षम कर सकता हूं? के लिए किसी कारण मैं जंगली अनुमति मूल और हेडर carded अभी तक अपने ajax अनुरोध अभी भी शिकायत है कि मूल मेरी CORS नीति द्वारा अनुमति नहीं थी ....सीओआरएस नीति
मेरे अनुप्रयोगों नियंत्रक:
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :current_user, :cors_preflight_check
after_filter :cors_set_access_control_headers
# For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Allow-Headers'] = '*'
headers['Access-Control-Max-Age'] = "1728000"
end
# If this is a preflight OPTIONS request, then short-circuit the
# request, return only the necessary headers and return an empty
# text/plain.
def cors_preflight_check
if request.method == :options
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Allow-Headers'] = '*'
headers['Access-Control-Max-Age'] = '1728000'
render :text => '', :content_type => 'text/plain'
end
end
private
# get the user currently logged in
def current_user
@current_user ||= User.find(session[:user_id]) if session[:user_id]
end
helper_method :current_user
end
मार्गों:
match "*all" => "application#cors_preflight_check", :constraints => { :method => "OPTIONS" }
match "/alert" => "alerts#create"
match "/alerts" => "alerts#get"
match "/login" => "sessions#create"
match "/logout" => "sessions#destroy"
match "/register" => "users#create"
संपादित करें ---
मैं भी करने की कोशिश की:
config.middleware.use Rack::Cors do
allow do
origins '*'
resource '*',
:headers => :any,
:methods => [:get, :post, :delete, :put, :options]
end
end
application.rb
--edit 2 में
---
समस्या यह है कि क्रोम एक्सटेंशन CORS मुझे लगता है कि समर्थन नहीं कर सकते है। मैं सीओआरएस को छोड़कर जानकारी कैसे प्राप्त कर सकता हूं? मुझे प्रीफलाइट चेक का जवाब कैसे देना चाहिए?
नहीं "अक्षम CORS" का उपयोग नहीं करते लेकिन प्रभावी रूप से कोई नीति नहीं हो सकती है? मैं किसी भी अनुरोध का जवाब नहीं दे सकता। – Nonconformist
क्या आप इसे स्थानीयहोस्ट पर उपयोग करते हैं? – nXqd