gpt4 book ai didi

javascript - RoutingError(没有路由匹配[选项]

转载 作者:行者123 更新时间:2023-11-28 02:18:55 25 4
gpt4 key购买 nike

简单:一方面 Angularjs 在服务器上运行

'use strict'

### Sevices ###

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

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

另一边是在另一台服务器上运行的 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'

我不明白,因为我已经有一个在这个后端正常运行的backbonejs..backbonejs,虽然不发送 OPTIONS 请求...

在我的 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

我自己找到了解决方案:

    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)
])

关于javascript - RoutingError(没有路由匹配[选项],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15964558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com