简体   繁体   English

RoutingError(没有匹配的路由[OPTIONS]

[英]RoutingError (No route matches [OPTIONS]

Simple: on one side Angularjs running on a server 简单:一方面在服务器上运行Angularjs

'use strict'

### Sevices ###

angular.module('app.services', [])

.factory 'Contents', ($resource) ->
      Contents = $resource('http://127.0.0.1\\:3000/documents.json')

on the other side a rails back end running on another server 另一方面,Rails后端在另一台服务器上运行

Started OPTIONS "/documents.json" for 127.0.0.1 at 2013-04-12 15:22:27 +0900

ActionController::RoutingError (No route matches [OPTIONS] "/documents.json"):
  actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.12) lib/rails/rack/logger.rb:32:in `call_app'
  railties (3.2.12) lib/rails/rack/logger.rb:16:in `block in call'
  activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in `tagged'
  railties (3.2.12) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.12) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.12) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.12) lib/rails/engine.rb:479:in `call'
  railties (3.2.12) lib/rails/application.rb:223:in `call'
  rack (1.4.5) lib/rack/content_length.rb:14:in `call'
  railties (3.2.12) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
  /Users/mikael/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
  /Users/mikael/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
  /Users/mikael/.rvm/rubies/ruby-1.9.3-p362/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

I don t get it because I already have a backbonejs running properly with this backend.. backbonejs, doesn t send an OPTIONS request though... 我没有得到它,因为我已经有一个使用此后端正常运行的lobb.js。尽管如此,bobsjs并没有发送OPTIONS请求。

in my rails project I set up my Header directly in the code for now because I m using Webrick for development: 在我的rails项目中,我现在直接在代码中直接设置Header,因为我正在使用Webrick进行开发:

class ApplicationController < ActionController::Base
  protect_from_forgery
  after_filter :set_access_control_headers

  def set_access_control_headers
    headers['Access-Control-Allow-Origin'] = '*'
    headers['Access-Control-Request-Method'] = '*'
    headers['Access-Control-Allow-Headers'] = '*'
  end
end

Found the solution by myself: 自己找到了解决方案:

    App.config([
  '$routeProvider'
  '$httpProvider'
  '$locationProvider'

($routeProvider, $httpProvider, $locationProvider, config) ->

  $routeProvider

    .when('/contents', {templateUrl: '/partials/contents.html'})
    .when('/view1', {templateUrl: '/partials/partial1.html'})
    .when('/view2', {templateUrl: '/partials/partial2.html'})

    # Catch all
    .otherwise({redirectTo: '/contents'})

  delete $httpProvider.defaults.headers.common["X-Requested-With"]

  # Without server side support html5 must be disabled.
  $locationProvider.html5Mode(false)
])
App.config([
  '$routeProvider'
  '$httpProvider'
  '$locationProvider'

  ($routeProvider, $httpProvider, $locationProvider, config) ->

  $routeProvider

    .when('/contents', {templateUrl: '/partials/contents.html'})
    .when('/view1', {templateUrl: '/partials/partial1.html'})
    .when('/view2', {templateUrl: '/partials/partial2.html'})

    # Catch all
    .otherwise({redirectTo: '/contents'})

  delete $httpProvider.defaults.headers.common["X-Requested-With"]

  # Without server side support html5 must be disabled.
  $locationProvider.html5Mode(false)
])

This helped me found here: AngularJS performs an OPTIONS HTTP request for a cross-origin resource 这帮助我在这里找到: AngularJS对跨域资源执行OPTIONS HTTP请求

  app.config(['$httpProvider', function ($httpProvider) {
  //Reset headers to avoid OPTIONS request (aka preflight)
  $httpProvider.defaults.headers.common = {};
  $httpProvider.defaults.headers.post = {};
  $httpProvider.defaults.headers.put = {};
  $httpProvider.defaults.headers.patch = {};
}]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails CORS:ActionController::RoutingError(没有路由匹配 [OPTIONS] &quot;/batches&quot;): - Rails CORS: ActionController::RoutingError (No route matches [OPTIONS] "/batches"): RoutingError没有与[GET]“ /missing.png”匹配的路由 - RoutingError No route matches [GET] “/missing.png” ActionController :: RoutingError(没有路由与[GET]匹配” / assets / javascripts - ActionController::RoutingError (No route matches [GET] "/assets/javascripts 为什么存在路由可以视为没有路由匹配(RoutingError)? - Why does the route exist can be regarded as no route matches(RoutingError)? ActionController :: RoutingError(没有路由与[GET]“ / javascripts / application.js”匹配) - ActionController::RoutingError (No route matches [GET] “/javascripts/application.js”) ActionController :: RoutingError(没有路由与[GET] controller_name / fusioncharts.widgets.js匹配 - ActionController::RoutingError (No route matches [GET] controller_name/fusioncharts.widgets.js Ruby on Rails:PDF.JS ActionController :: RoutingError(没有路由与[GET]“ / pdf js / web / viewer.html”匹配): - Ruby on Rails: PDF.JS ActionController::RoutingError (No route matches [GET] “/pdf js/web/viewer.html”): 为什么我得到这个 ActionController::RoutingError (没有路由匹配 [GET] “/users/assets/application.js”) - Why I am getting this ActionController::RoutingError (No route matches [GET] “/users/assets/application.js”) 如何找到导致ActionController :: RoutingError的原因,没有路由匹配错误? - How can I find what is causing the ActionController::RoutingError No route matches error? ActionController :: RoutingError(没有路由匹配[GET]“/members/js/bootstrap.min.js&quot;):(Missing资产文件) - ActionController::RoutingError (No route matches [GET] “/members/js/bootstrap.min.js”):(Missing Asset files)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM