0

所以我最近rack-pjax在我的应用程序中安装了它,所以一些侧边栏不会重新加载导航,我让它在开发中工作,但是当我把它推到 heroku 时,由于某种原因,它不起作用。

如果我导航到“/music”,它会重新加载整个页面,URL 从“/music”到“/music#”再返回到“/music”。

编辑 {

在 heroku 日志中,您可以看到它两次发送 GET 请求,这解释了 URL 中的差异。如果第二个 GET 请求没有发生,它应该可以工作。

}

这是我在开发中做的日志:

J-Laptop:pregun joeshoulak$ rails s
WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.8
=> Booting Thin
=> Rails 3.2.13 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.1 codename Straight Razor)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop


Started GET "/" for 127.0.0.1 at 2013-07-11 18:15:31 -0500
Processing by StaticPagesController#home as HTML
  Rendered static_pages/home.html.erb within layouts/application (15.1ms)
Compiled static_pages.js  (604ms)  (pid 33288)
Compiled application.js  (7ms)  (pid 33288)
  Rendered layouts/_header.html.erb (1115.5ms)
  Rendered layouts/_subscribe.html.erb (440.1ms)
  Rendered layouts/_soundcloud.html.erb (0.4ms)
  Rendered layouts/_tweet-stream.html.erb (0.4ms)
  Rendered layouts/_footer.html.erb (0.4ms)
  Rendered layouts/_google_analytics.html.erb (0.5ms)
Completed 200 OK in 1719ms (Views: 1718.8ms | ActiveRecord: 0.0ms)


Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /application.css - 304 Not Modified (11ms)


Started GET "/assets/jquery.fancybox.css?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /jquery.fancybox.css - 304 Not Modified (3ms)


Started GET "/assets/fancybox.css?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /fancybox.css - 304 Not Modified (4ms)


Started GET "/assets/email.css?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /email.css - 304 Not Modified (1ms)


Started GET "/assets/forms.css?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /forms.css - 304 Not Modified (1ms)


Started GET "/assets/static_pages.css?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /static_pages.css - 304 Not Modified (5ms)


Started GET "/assets/users.css?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /users.css - 304 Not Modified (3ms)


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /jquery.js - 304 Not Modified (3ms)


Started GET "/assets/jquery.browser.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /jquery.browser.js - 304 Not Modified (2ms)


Started GET "/assets/jquery.fancybox.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /jquery.fancybox.js - 304 Not Modified (2ms)


Started GET "/assets/fancybox.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /fancybox.js - 304 Not Modified (4ms)


Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /jquery_ujs.js - 304 Not Modified (26ms)


Started GET "/assets/jquery.pjax.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /jquery.pjax.js - 304 Not Modified (1ms)


Started GET "/assets/email.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /email.js - 304 Not Modified (2ms)


Started GET "/assets/fonts.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /fonts.js - 304 Not Modified (1ms)


Started GET "/assets/static_pages.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /static_pages.js - 304 Not Modified (2ms)


Started GET "/assets/users.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /users.js - 304 Not Modified (2ms)


Started GET "/assets/application.js?body=1" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /application.js - 304 Not Modified (13ms)


Started GET "/assets/photos/small/on-stage.jpg" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /photos/small/on-stage.jpg - 304 Not Modified (18ms)


Started GET "/assets/photos/small/model.jpg" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /photos/small/model.jpg - 304 Not Modified (60ms)


Started GET "/assets/wood-tile.jpg" for 127.0.0.1 at 2013-07-11 18:15:33 -0500
Served asset /wood-tile.jpg - 304 Not Modified (21ms)


Started GET "/music?_pjax=%5Bdata-pjax-container%5D" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Processing by StaticPagesController#music as HTML
  Parameters: {"_pjax"=>"[data-pjax-container]"}
  Rendered static_pages/music.html.erb within layouts/application (1.0ms)
  Rendered layouts/_header.html.erb (58.6ms)
  Rendered layouts/_subscribe.html.erb (5.1ms)
  Rendered layouts/_soundcloud.html.erb (0.1ms)
  Rendered layouts/_tweet-stream.html.erb (0.1ms)
  Rendered layouts/_footer.html.erb (0.1ms)
  Rendered layouts/_google_analytics.html.erb (0.1ms)
Completed 200 OK in 194ms (Views: 193.9ms | ActiveRecord: 0.0ms)


Started GET "/assets/photos/small/on-stage.jpg" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Served asset /photos/small/on-stage.jpg - 304 Not Modified (0ms)


Started GET "/assets/photos/small/model.jpg" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Served asset /photos/small/model.jpg - 304 Not Modified (0ms)


Started GET "/assets/albums/accident.jpg" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Served asset /albums/accident.jpg - 304 Not Modified (29ms)


Started GET "/assets/albums/forever.jpg" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Served asset /albums/forever.jpg - 304 Not Modified (48ms)


Started GET "/assets/albums/green.jpg" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Served asset /albums/green.jpg - 304 Not Modified (1ms)


Started GET "/assets/albums/recluse.jpg" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Served asset /albums/recluse.jpg - 304 Not Modified (1ms)


Started GET "/assets/albums/gone.jpg" for 127.0.0.1 at 2013-07-11 18:15:44 -0500
Served asset /albums/gone.jpg - 304 Not Modified (43ms)

当我在生产中尝试相同的事情时,这是我的 Heroku 日志。

2013-07-11T23:18:51.945015+00:00 heroku[web.1]: Starting process with command `bundle exec thin start -R config.ru -e $RAILS_ENV -p 6327`
2013-07-11T23:18:58.952314+00:00 app[web.1]: WARNING: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.6
2013-07-11T23:18:59.160588+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-07-11T23:18:59.160588+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5)
2013-07-11T23:19:03.265277+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2013-07-11T23:19:04.697633+00:00 app[web.1]: >> Maximum connections set to 1024
2013-07-11T23:19:04.697633+00:00 app[web.1]: >> Thin web server (v1.5.1 codename Straight Razor)
2013-07-11T23:19:04.697633+00:00 app[web.1]: >> Listening on 0.0.0.0:6327, CTRL+C to stop
2013-07-11T23:19:05.032735+00:00 heroku[web.1]: State changed from starting to up
2013-07-11T23:19:07.649643+00:00 app[web.1]: Started GET "/" for 65.103.31.9 at 2013-07-11 23:19:07 +0000
2013-07-11T23:19:07.751857+00:00 app[web.1]: Processing by StaticPagesController#home as HTML
2013-07-11T23:19:07.819355+00:00 app[web.1]:   Rendered layouts/_header.html.erb (2.5ms)
2013-07-11T23:19:07.810610+00:00 app[web.1]:   Rendered static_pages/home.html.erb within layouts/application (5.1ms)
2013-07-11T23:19:08.128110+00:00 heroku[router]: at=info method=GET path=/ host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=439ms status=304 bytes=0
2013-07-11T23:19:08.079075+00:00 app[web.1]:   Rendered layouts/_tweet-stream.html.erb (0.2ms)
2013-07-11T23:19:08.078419+00:00 app[web.1]:   Rendered layouts/_soundcloud.html.erb (0.6ms)
2013-07-11T23:19:08.079684+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.2ms)
2013-07-11T23:19:08.080610+00:00 app[web.1]: Completed 200 OK in 329ms (Views: 328.3ms | ActiveRecord: 0.0ms)
2013-07-11T23:19:08.077263+00:00 app[web.1]:   Rendered layouts/_subscribe.html.erb (257.2ms)
2013-07-11T23:19:08.080442+00:00 app[web.1]:   Rendered layouts/_google_analytics.html.erb (0.4ms)
2013-07-11T23:19:09.490768+00:00 heroku[router]: at=info method=GET path=/assets/application-e4de29223b008b9aab08de9e9baf133e.css host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=3ms service=8ms status=304 bytes=0
2013-07-11T23:19:10.865673+00:00 heroku[router]: at=info method=GET path=/assets/application-4502e11f3b6bc00a0e152e2b246a1548.js host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=5ms status=304 bytes=0
2013-07-11T23:19:12.729769+00:00 heroku[router]: at=info method=GET path=/assets/photos/small/model.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=583ms status=304 bytes=0
2013-07-11T23:19:12.731088+00:00 heroku[router]: at=info method=GET path=/assets/photos/small/on-stage.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=592ms status=304 bytes=0
2013-07-11T23:19:13.259316+00:00 heroku[router]: at=info method=GET path=/assets/wood-tile.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=8ms status=304 bytes=0
2013-07-11T23:19:27.016512+00:00 app[web.1]: Started GET "/music?_pjax=%5Bdata-pjax-container%5D" for 65.103.31.9 at 2013-07-11 23:19:27 +0000
2013-07-11T23:19:27.099811+00:00 app[web.1]: Processing by StaticPagesController#music as HTML
2013-07-11T23:19:27.114816+00:00 app[web.1]:   Rendered layouts/_subscribe.html.erb (2.5ms)
2013-07-11T23:19:27.112042+00:00 app[web.1]:   Rendered layouts/_header.html.erb (1.2ms)
2013-07-11T23:19:27.115623+00:00 app[web.1]:   Rendered layouts/_tweet-stream.html.erb (0.0ms)
2013-07-11T23:19:27.115386+00:00 app[web.1]:   Rendered layouts/_soundcloud.html.erb (0.0ms)
2013-07-11T23:19:27.110545+00:00 app[web.1]:   Rendered static_pages/music.html.erb within layouts/application (1.1ms)
2013-07-11T23:19:27.106652+00:00 app[web.1]:   Parameters: {"_pjax"=>"[data-pjax-container]"}
2013-07-11T23:19:27.141265+00:00 app[web.1]:   Rendered layouts/_google_analytics.html.erb (0.0ms)
2013-07-11T23:19:27.155659+00:00 heroku[router]: at=info method=GET path=/music?_pjax=%5Bdata-pjax-container%5D host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=141ms status=200 bytes=1194
2013-07-11T23:19:27.141265+00:00 app[web.1]: Completed 200 OK in 32ms (Views: 31.0ms | ActiveRecord: 0.0ms)
2013-07-11T23:19:27.141265+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.0ms)
2013-07-11T23:19:27.663407+00:00 app[web.1]: Processing by StaticPagesController#music as HTML
2013-07-11T23:19:27.660457+00:00 app[web.1]: Started GET "/music" for 65.103.31.9 at 2013-07-11 23:19:27 +0000
2013-07-11T23:19:27.678623+00:00 heroku[router]: at=info method=GET path=/music host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=13ms status=304 bytes=0
2013-07-11T23:19:27.667604+00:00 app[web.1]:   Rendered layouts/_header.html.erb (1.8ms)
2013-07-11T23:19:27.669287+00:00 app[web.1]:   Rendered layouts/_soundcloud.html.erb (0.0ms)
2013-07-11T23:19:27.669121+00:00 app[web.1]:   Rendered layouts/_subscribe.html.erb (1.3ms)
2013-07-11T23:19:27.669450+00:00 app[web.1]:   Rendered layouts/_tweet-stream.html.erb (0.0ms)
2013-07-11T23:19:27.669992+00:00 app[web.1]: Completed 200 OK in 6ms (Views: 6.3ms | ActiveRecord: 0.0ms)
2013-07-11T23:19:27.665544+00:00 app[web.1]:   Rendered static_pages/music.html.erb within layouts/application (1.3ms)
2013-07-11T23:19:27.669773+00:00 app[web.1]:   Rendered layouts/_google_analytics.html.erb (0.0ms)
2013-07-11T23:19:27.669617+00:00 app[web.1]:   Rendered layouts/_footer.html.erb (0.0ms)
2013-07-11T23:19:29.241509+00:00 heroku[router]: at=info method=GET path=/assets/albums/forever.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=4ms status=304 bytes=0
2013-07-11T23:19:30.839296+00:00 heroku[router]: at=info method=GET path=/assets/albums/green.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=2ms service=3ms status=304 bytes=0
2013-07-11T23:19:30.843345+00:00 heroku[router]: at=info method=GET path=/assets/albums/recluse.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=3ms status=304 bytes=0
2013-07-11T23:19:30.853211+00:00 heroku[router]: at=info method=GET path=/assets/albums/gone.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=3ms status=304 bytes=0
2013-07-11T23:19:29.237902+00:00 heroku[router]: at=info method=GET path=/assets/albums/accident.jpg host=www.prestongunderson.com fwd="65.103.31.9" dyno=web.1 connect=1ms service=4ms status=304 bytes=0

以下是 pjax 的相关文件:

/config/application.rb:

require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
  Bundler.require(*Rails.groups(:assets => %w(development test)))
end

module Prestongunderson
  class Application < Rails::Application
    config.middleware.use Rack::Pjax
    config.encoding = "utf-8"
    config.filter_parameters += [:password]
    config.active_support.escape_html_entities_in_json = true

    config.active_record.whitelist_attributes = true
    config.assets.enabled = true
    config.assets.version = '1.0'
  end
end

/assets/javascripts/application.js //= 需要 jquery //= 需要 fancybox //= 需要 jquery_ujs //= 需要 jquery.pjax //= require_tree 。

/assets/javascripts/static_pages.js.coffee

$(document).ready ->
    jQuery ->
    $("a.fancybox").fancybox()
    jQuery ->
    $(document).pjax('a.local-nav', '[data-pjax-container]')

/app/views/layouts/application.html.erb

<!DOCTYPE html>
<html>
    <%= render 'layouts/header' %>
    <%= render 'layouts/subscribe' %>
    <%= render 'layouts/soundcloud' %>
    <%= render 'layouts/tweet-stream' %>

    <body>

        <div data-pjax-container>
          <%= yield %>
        </div>

        <%= render 'layouts/footer' %>
        <%= render 'layouts/google_analytics' %>
    </body>
</html>

/app/views/layouts/_header.html.erb

<head>
    <% @title = yield(:title) %>
    <title>Preston Gunderson | <%= @title %></title>
    <%= stylesheet_link_tag     'http://fonts.googleapis.com/css?family=Fauna+One|Mr+Bedfort|Milonga' %>
    <%= stylesheet_link_tag     'application', :media => 'all' %>
    <%= javascript_include_tag  'application' %>
    <%= csrf_meta_tags %>
</head>

<% if flash[:notice] %>
    <div class='alert'><%= flash[:notice] %></div>
        <style>
            #subscribe, #soundcloud {
                top: 60px;
            }
            #tweet-stream {
                top: 200px;
            }
        </style>
<% end %>
<nav class='center border'> 
    <ul>
        <% ['Home', 'Bio', 'Gallery', 'Music', 'Tour', 'Videos', 'Contact'].each do |page| %>
            <li><%= link_to( page.upcase, "/#{page.downcase}", class: 'local-nav') %></li>
        <% end %>
        <li><%= link_to( 'MERCH', 'https://prestongunderson.bigcartel.com') %></li>
    </ul>
</nav>
<header class='center border' id='head-box'>
    <p id='supertitle'>The official site of Singer Songwriter</p>
    <h1>Preston Gunderson</h1>
</header>

/宝石文件

source 'https://rubygems.org'

gem 'rails', '3.2.13'
gem 'bootstrap-sass', '2.1'
gem 'simple_form'
gem 'rspec'
gem 'pg'
gem 'jquery-rails'
gem 'fancybox-rails'
gem 'thin'
gem 'rack-pjax'

group :development, :test do 
  gem 'sqlite3'
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end
4

1 回答 1

1

在调用 pjax 之前,请尝试将其添加到 JavaScript:

$(document).on('pjax:timeout', function() {
    return false;
});

这将禁用超时。我遇到了同样的问题,问题是我的应用程序太慢,加载时间太长,pjax 会取消请求并发送浏览器。您当然可以增加超时时间,但我认为这更好。

于 2013-08-13T17:45:18.360 回答