11

突然,当我在本地运行我的应用程序时,我得到了双控制台输出。有谁知道这可能是什么原因造成的?运行 Thin 和 Unicorn 时都存在问题

=> Booting Thin
=> Rails 4.0.0 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> 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-09-05 22:21:21 +0200
Started GET "/" for 127.0.0.1 at 2013-09-05 22:21:21 +0200
Processing by HomeController#index as HTML
Processing by HomeController#index as HTML
  Rendered home/index.html.erb within layouts/application (299.5ms)
  Rendered home/index.html.erb within layouts/application (299.5ms)
  Rendered layouts/_navbar.html.erb (38.3ms)
  Rendered layouts/_navbar.html.erb (38.3ms)
  Rendered layouts/_footer.html.erb (0.8ms)
  Rendered layouts/_footer.html.erb (0.8ms)
Completed 200 OK in 704ms (Views: 428.1ms | ActiveRecord: 52.4ms)
Completed 200 OK in 704ms (Views: 428.1ms | ActiveRecord: 52.4ms)

这是我的宝石文件

# Gemfile
source 'https://rubygems.org'

ruby '2.0.0'

gem 'rails'

gem 'actionpack-action_caching'
gem 'asset_sync'
gem 'authlogic', github: 'binarylogic/authlogic'
gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass', branch: '3'
gem 'coffee-rails'
gem 'dalli'
gem 'font-awesome-rails'
gem 'highcharts-rails'
gem 'jbuilder'
gem 'jquery-rails'
gem 'memcachier'
gem 'newrelic_rpm'
gem 'pg'
gem 'prawn', '>= 1.0.0.rc2'
gem 'prawn_rails'
gem 'rack-mini-profiler', require: 'rack-mini-profiler'
gem 'rack-timeout'
gem 'rails-i18n'
gem 'rails_12factor' # required by Heroku
gem 'sass-rails'
gem 'uglifier'
gem 'yui-compressor'

group :production do
  gem 'justonedb'
  gem 'unicorn-rails'
end

group :development do
  gem 'annotate'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'hirb'
  gem 'lol_dba' # To find table in need of indexes run 'lol_dba db:find_indexes'
  gem 'mailcatcher'
  gem 'pry'
  gem 'quiet_assets'
end

group :test do
  gem 'capybara'
  gem 'capybara-webkit'
  gem 'factory_girl_rails', require: false
  gem 'fuubar'
  gem 'rspec-rails'
  gem 'rails_12factor'
end

我的发展.rb

# development.rb
Beerclub::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb.
  config.log_level = :debug

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Don't care if the mailer can't send.
  config.action_mailer.raise_delivery_errors = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.compress = false
  config.assets.debug = true
  config.serve_static_assets = true
end

和 application.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module Beerclub
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    config.time_zone = 'Copenhagen'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    config.i18n.default_locale = :da

    # Enable the asset pipeline
    config.assets.enabled = true
    config.assets.version = '1.0'

    # Needs to be false on Heroku
    config.serve_static_assets = false
    config.static_cache_control = "public, max-age=31536000"

    # Add the fonts path
    config.assets.paths << Rails.root.join('app', 'assets', 'fonts')
    config.assets.paths << Rails.root.join('vendor', 'assets', 'fonts')

    # Precompile additional assets
    config.assets.precompile += %w( *.svg *.eot *.woff *.ttf )
    config.assets.precompile += %w( *.png *.jpg *.jpeg *.gif )
  end
end
4

6 回答 6

12

关于 rails_12factor - 如果您将 Gemfile 中的行更改为:

gem 'rails_12factor', group: :production

在调试等时,您将不再在控制台中看到双重输出。

于 2014-10-27T20:01:38.040 回答
11

我注意到这是因为rails_12factor宝石而发生的。gem rails_12factor如果你从你的双重输出中注释掉Gemfile应该消失。我的猜测是,双重输出并不重要,因为 Heroku 无论如何都需要 gem。至于为什么rails_12factor宝石会导致这个我不知道。

于 2013-11-03T08:26:23.807 回答
1

检查您的应用程序中是否有这样的代码:

<img src="#">

Rails 有时也会因此产生重复记录。

您可以尝试这样做:

rake assets:clean

或者,也许,在 development.rb 中注释掉这一行,可能会起作用:

config.active_support.deprecation = :log

作为最后一次尝试,您甚至可以尝试更改应用程序的文件夹,然后启动服务器以查看结果。

干杯!

于 2013-09-23T19:14:32.440 回答
0

从您的示例中,它表明重复正在内联发生,即。

A
A
B
B
C
C

相反,如果您看到似乎是两个背靠背重复请求,即:

A
B
C

A
B
C

您应该强烈考虑@aelor 寻找一个<img src="#">或类似的自引用 url 标签的答案。我花了几个小时试图弄清楚为什么我的应用程序似乎提出了两个重复的请求,在阅读了@aelor 的答案后,我发现

%link{href: "", rel: "shortcut icon"}/

在我的代码中!它导致我的生产应用程序的每个页面都被双重渲染!!!!性能太差,太烦人了!

于 2015-02-03T12:29:01.360 回答
0

在 Rails 4.2 和本文发布时,我知道的唯一解决方案是从 Gemfile 中删除 rails_12factor。

添加group: :production不再阻止双重记录。github上的heroku有一个未解决的问题:

https://github.com/heroku/rails_stdout_logging/issues/1

于 2015-09-11T23:57:10.227 回答
0

我们发现这是由运行 Rails 服务器引起的

$ rails server

而不是

$ thin start

使用后者时,双重记录问题就消失了。不幸的是,我们没有时间锁定原因,我们只是改变了推出 Thin 的方式并继续前进。

于 2015-10-02T04:55:06.983 回答