【问题标题】:Angular + Rails app hang up whole browser when trying to fetch subpageAngular + Rails 应用程序在尝试获取子页面时挂起整个浏览器
【发布时间】:2013-04-21 14:48:28
【问题描述】:

我正在使用 Angular 和 Rails 编写应用程序。我的ApplicationController 有后备:

class ApplicationController < ActionController::Base
  protect_from_forgery

  before_filter :intercept_html_requests

  private

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

和路由器一样:

betly.config(function($routeProvider, $locationProvider) {
  $locationProvider.html5Mode(true);

  $routeProvider.when('/', {
    templateUrl: 'assets/tournaments.html',
    controller: 'tournamentController'
  }).when('/aaa', {
    templateUrl: 'assets/tournaments.html',
    controller: 'tournamentController'
  }).when('/matches/:matchId',{
    templateUrl: 'assets/matchDetails.html',
    controller: 'matchController'
  }).otherwise({
    redirectTo:'/'
  });
});

views/layouts/application.html.erb:

<!DOCTYPE html>
<html lang="en" ng-app>
  <head>
    <meta charset='utf-8' />
    <title>BetLy</title>
    <%= stylesheet_link_tag    "application", media: "all" %>
    <%= csrf_meta_tags %>
  </head>
  <body>
    <%= yield %>
    <%= javascript_include_tag "application" %>
  </body>
</html>

当我尝试访问/matches/10 时,浏览器会无限下载资产。为什么以及如何解决这个问题?

【问题讨论】:

  • 我遇到了同样的问题

标签: ruby-on-rails angularjs asset-pipeline pushstate


【解决方案1】:

问题出在路由文件中。当您尝试在 Rails 应用程序中捕获所有路线时,不应在路线中添加 /,因此它应如下所示:

match '*any', to: 'controller#method'

而不是

match '/*any', to: 'controller#method'

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 2021-06-24
    • 1970-01-01
    • 2021-11-18
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 2013-03-17
    相关资源
    最近更新 更多