25 Temmuz 2013, PERŞEMBE
KÖŞELERİ İlkesi hiçbir şeyin geçmesine izin ver
Nasıl bir istasyondan devre dışı bırakabilir miyim? Nedense ben vahşi izin kökenleri ve başlıkları henüz karde benim ajax istekleri hala kökeni benim bir İSTASYONDAN İlkesi tarafından izin verilmedi şikayet....
Uygulamalar benim denetleyicisi :
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
güzergah:
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"
Edit---
Ben de denedim:
config.middleware.use Rack::Cors do
allow do
origins '*'
resource '*',
:headers => :any,
:methods => [:get, :post, :delete, :put, :options]
end
end
uygulamada.rb
2 - - - --düzenleyin
Sorun Chrome Uzantıları sanırım bir İSTASYONDAN desteklemiyor olabilir. Nasıl bilgi atlayarak bir İSTASYONDAN alabilir miyim? Nasıl ön kontrol, karşılık vermeliyim?
CEVAP
14 AĞUSTOS 2013, ÇARŞAMBA
Hangi raylar-apı kullanılan ortak bir API aynı gereksinimlerinizi ettim.
Ayrıca Başlığı önce filtre olarak ayarladım. Bu gibi görünüyor:
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = '*'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
Access-Control-İstek-Yöntem Başlığı kaçırdın galiba.
Bunu Paylaş:
KÖŞELERİ Heroku üzerinde Express/Node....
't değil o metin girişi ile JQuer...
UİSearchDisplayController hiçbir sonuç...
VS2010 proje güncel değil ama hiçbir ş...
EF Code First "Geçersiz sütun...