Как избавиться от заблокированного запроса перекрестного происхождения: в рельсах 4

Подскажите, пожалуйста, где я ошибся, и есть ли что-то, что я должен добавить, чтобы получить json с сайта heroku?

config.ru

require ::File.expand_path('../config/environment', __FILE__)

run Rails.application
use Rack::Cors do
allow do
origins 'localhost:3000', '127.0.0.1:3000', 'http://stark-anchorage-86169.herokuapp.com/ages/    getfortest', /\Ahttp:\/\/192\.168\.0\.\d{1,3}(:\d+)?\z/


resource '/file/list_all/', :headers => 'x-domain-token'
resource '/file/at/*',
    :methods => [:get, :post, :delete, :put, :patch, :options, :head],
    :headers => 'x-domain-token',
    :expose  => ['Some-Custom-Response-Header'],
    :max_age => 600

end

 allow do
 origins '*'
 resource '/public/*', :headers => :any, :methods => :get
 end
 end

конфиг /application.rb

Bundler.require(*Rails.groups)

module AppV11
class Application < Rails::Applications.



config.active_record.raise_in_transactional_callbacks = true

config.middleware.insert_before 0, "Rack::Cors" do
  allow do
    origins '*'
    resource '*', :headers => :any, :methods => [:get, :post, :options]
  end
end
end

end

Мой контроллер выглядит так с некоторыми помощниками ниже

before_filter :set_access_control_headers

def set_access_control_headers
headers['Access-Control-Allow-Origin'] = 'http://staranchorage-          86169.herokuapp.com/ages/getfortest'
end

Часть Angularjs:

function getpost()
 {
     console.log("INSIDE GETPOST");
     $http.get('http://stark-anchorage-86169.herokuapp.com/ages/getfortest')
     .success(function(response)
             {
         console.log("INSIDE RESPONSE "+ response);
         $scope.demogetpost = response.data;
         console.log( $scope.demogetpost);
         console.log("NOT PRINTING");
     })
     return $scope.demogetpost;
 }

1 ответ

Я открываю новую вкладку, и по этой причине я заблокировал запрос Cross-Origin. Также я добавил заголовки для Access-Control-Allow-Origin.

Другие вопросы по тегам