Rails + AngularJS - 页面刷新不适用于localhost

时间:2017-02-16 11:56:56

标签: javascript ruby-on-rails angularjs heroku

我正在研究Rails 4.2 + AngularJS 1.5项目并遇到了非常奇怪的问题。当我试图刷新(F5)我的项目的主要网页时,很有可能(让他们说9/10)刷新将无法正常执行。在这种情况下,我看到的只是application.html.haml布局内容(例如" ToDoDoo"标题):

!!!
%html{"ng-app" => "tododoo"}
  %head
    %title Tododoo
    = stylesheet_link_tag    'application', media: 'all'
    = javascript_include_tag 'application'
    = csrf_meta_tags
  %body
    .row#header-row
      .col-md-8.col-md-offset-2
        %h1#main-header
          ToDoDoo

    = yield

有机会1/10它将正确刷新页面,在这种情况下,我会看到我的布局内容以及实际应在/路线上呈现的角度模板。它位于app/assets/javascripts/templates/projects/index.html.haml。现在我不认为它的代码对我的问题非常重要,但是如果你想看到它,我会添加它。

更新:如果我的服务器控制台中的刷新效果很好:

Started GET "/" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by MainController#index as HTML
  Rendered main/index.html.haml within layouts/application (0.1ms)
Completed 200 OK in 54ms (Views: 53.3ms | ActiveRecord: 0.0ms)


Started GET "/assets/bg.jpg" for 127.0.0.1 at 2017-02-16 15:15:35 +0200


Started GET "/projects?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by ProjectsController#index as JSON
  Project Load (0.4ms)  SELECT "projects".* FROM "projects" WHERE "projects"."user_id" = $1  [["user_id", 2]]
  Task Load (0.4ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 4]]
  Comment Load (0.4ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 26]]
  Rendered projects/_comment.json.jbuilder (0.2ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (8.6ms)
  Comment Load (0.4ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 27]]
  Rendered projects/_comment.json.jbuilder (0.2ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.2ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.3ms)
  Rendered projects/_comment.json.jbuilder (0.5ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.3ms)
  Rendered shared/_task.json.jbuilder (14.7ms)
  Comment Load (0.4ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 28]]
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (4.4ms)
  Rendered projects/_project.json.jbuilder (33.1ms)
  Task Load (1.6ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 5]]
  Comment Load (0.4ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 29]]
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (7.0ms)
  Rendered projects/_project.json.jbuilder (12.7ms)
  Task Load (0.4ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 6]]
  Comment Load (0.3ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 30]]
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (8.0ms)
  Comment Load (1.8ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 31]]
  Rendered projects/_comment.json.jbuilder (0.2ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (23.2ms)
  Comment Load (1.5ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 32]]
  Rendered projects/_comment.json.jbuilder (0.5ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.2ms)
  Rendered projects/_comment.json.jbuilder (0.2ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (20.0ms)
  Comment Load (1.2ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 33]]
  Rendered projects/_comment.json.jbuilder (0.2ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (8.3ms)
  Comment Load (0.3ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 34]]
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered shared/_task.json.jbuilder (2.6ms)
  Comment Load (0.3ms)  SELECT "comments".* FROM "comments" WHERE "comments"."task_id" = $1  [["task_id", 35]]
  Rendered projects/_comment.json.jbuilder (0.1ms)
  Rendered projects/_comment.json.jbuilder (0.0ms)
  Rendered shared/_task.json.jbuilder (6.6ms)
  Rendered projects/_project.json.jbuilder (75.1ms)
  Rendered projects/index.json.jbuilder (135.1ms)
Completed 200 OK in 139ms (Views: 128.5ms | ActiveRecord: 9.8ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.2ms)
Completed 200 OK in 5ms (Views: 3.6ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.1ms)
Completed 200 OK in 6ms (Views: 3.9ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (1.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (2.6ms)
Completed 200 OK in 6ms (Views: 3.8ms | ActiveRecord: 1.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (0.9ms)
Completed 200 OK in 3ms (Views: 2.5ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (0.9ms)
Completed 200 OK in 5ms (Views: 4.0ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (0.9ms)
Completed 200 OK in 3ms (Views: 2.4ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (1.1ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (3.2ms)
Completed 200 OK in 8ms (Views: 5.3ms | ActiveRecord: 1.1ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (0.9ms)
Completed 200 OK in 4ms (Views: 2.6ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.0ms)
Completed 200 OK in 4ms (Views: 2.6ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.4ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.4ms)
Completed 200 OK in 6ms (Views: 4.3ms | ActiveRecord: 0.4ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.1ms)
Completed 200 OK in 4ms (Views: 2.9ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.4ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.1ms)
Completed 200 OK in 6ms (Views: 4.6ms | ActiveRecord: 0.4ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.1ms)
Completed 200 OK in 4ms (Views: 2.9ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.0ms)
Completed 200 OK in 4ms (Views: 2.7ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.4ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.0ms)
Completed 200 OK in 4ms (Views: 2.6ms | ActiveRecord: 0.4ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (0.9ms)
Completed 200 OK in 3ms (Views: 2.5ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.0ms)
Completed 200 OK in 4ms (Views: 2.6ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.3ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.1ms)
Completed 200 OK in 4ms (Views: 2.8ms | ActiveRecord: 0.3ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:35 +0200
Processing by TasksController#index as JSON
  Task Load (0.5ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (1.6ms)
Completed 200 OK in 5ms (Views: 4.0ms | ActiveRecord: 0.5ms)


Started GET "/tasks?format=json" for 127.0.0.1 at 2017-02-16 15:15:36 +0200
Processing by TasksController#index as JSON
  Task Load (0.6ms)  SELECT "tasks".* FROM "tasks" WHERE "tasks"."project_id" = $1  [["project_id", 1]]
  Rendered tasks/index.json.jbuilder (2.0ms)
Completed 200 OK in 6ms (Views: 4.4ms | ActiveRecord: 0.6ms)

如果不是,我只是:

Started GET "/" for 127.0.0.1 at 2017-02-16 15:16:00 +0200
Processing by MainController#index as HTML
  Rendered main/index.html.haml within layouts/application (0.1ms)
Completed 200 OK in 61ms (Views: 60.8ms | ActiveRecord: 0.0ms)


Started GET "/assets/bg.jpg" for 127.0.0.1 at 2017-02-16 15:16:00 +0200

但是!在Heroku上,页面刷新工作得很好!每次按下刷新按钮时刷新页面。它实际上让我觉得奇怪。我还在我的Rails应用程序上安装了Puma服务器而不是默认服务器(Webrick),用它启动了我的应用程序但是没有帮助。

所以如果你能告诉我我的设置有什么问题,我真的很感激吗?如果您需要查看任何代码或其他内容,请与我们联系。我只是不知道哪些代码有助于解决问题。

1 个答案:

答案 0 :(得分:0)

最终我找到了答案。问题是我在Chrome DevTools,AngularJS标签(由Batarang扩展提供)复选框“启用”选中。所以这就搞砸了。显然,应该取消选中该复选框并仅检查它是否实际调试应用程序。