Angularjs和Rails:html5mode导致无限页面加载

时间:2014-01-26 10:56:43

标签: ruby-on-rails angularjs

我在app.js中有以下配置:

$routeProvider.when('/signs/new', {
  templateUrl: 'templates/NewSign.html',
  controller:  'EditSignController'
});
$routeProvider.when('/signs', {
  templateUrl: 'templates/SignList.html',
  controller: 'SignListController'
});
$routeProvider.when('/signs/:signId', {
  templateUrl: 'templates/SignDetails.html',
  controller: 'SignController'
});
$routeProvider.otherwise({redirectTo: '/signs'});
$locationProvider.html5Mode(true);

我使用thin网络服务器。

routes.rb中:

Pdd::Application.routes.draw do
  resources :signs

  root to: "home#index"
  get '*path' => "home#index"

end

application_controller.rb

    class ApplicationController < ActionController::Base
      protect_from_forgery

      before_filter :intercept_html_requests
      after_filter :set_csrf_cookie_for_ng

      def set_csrf_cookie_for_ng
        cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
      end


      protected

      def verified_request?
        super || form_authenticity_token == request.headers['X-XSRF-TOKEN']
      end

      private

      def intercept_html_requests
        render('home/index') if request.format == Mime::HTML
      end

    end

路由/signs运行良好,但访问/signs/newsigns/1强制thin一次又一次地重新加载资源,因此页面无法加载,我只能杀死浏览器中的选项卡。我做错了什么?

0 个答案:

没有答案
相关问题