1

我将我的应用程序部署到 Heroku 上的临时应用程序。它在本地工作 100% 正常。

http://exposehair-staging.herokuapp.com

我有两个渲染 JS 的控制器。当我提交一个远程表单时,它会调用预期的操作并在其中执行代码......除了它没有呈现 JS 模板。正在对操作中的数据库进行更改,但这就是应用程序停止的地方。这发生在渲染 JS 的两个控制器上。请记住,该应用程序在本地开发模式下可以正常工作。

我想知道问题是否在于我的应用程序配置与 Heroku 一起使用?

这是我的 Heroku 应用程序日志:

2013-02-01T20:17:17+00:00 app[web.1]: Started GET "/" for 68.230.151.152 at 2013-02-01 20:17:17 +0000
2013-02-01T20:17:17+00:00 app[web.1]:   Rendered blurbs/_show.html.slim (2.3ms)
2013-02-01T20:17:12+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:10)
2013-02-01T20:17:12+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:10)
2013-02-01T20:17:08+00:00 heroku[web.1]: Starting process with command `bundle exec thin start -R config.ru -e staging -p 23436`
2013-02-01T20:17:15+00:00 app[web.1]: >> Thin web server (v1.5.0 codename Knife)
2013-02-01T20:17:15+00:00 app[web.1]: >> Maximum connections set to 1024
2013-02-01T20:17:15+00:00 app[web.1]: >> Listening on 0.0.0.0:23436, CTRL+C to stop
2013-02-01T20:17:17+00:00 app[web.1]: Completed 200 OK in 232ms (Views: 114.2ms | ActiveRecord: 63.0ms)
2013-02-01T20:17:17+00:00 app[web.1]: Processing by PagesController#index as HTML
2013-02-01T20:17:17+00:00 app[web.1]:   Rendered business_hours/_index.html.slim (24.9ms)
2013-02-01T20:17:17+00:00 app[web.1]:   Rendered pages/index.html.slim within layouts/application (78.4ms)
2013-02-01T20:17:18+00:00 heroku[router]: at=info method=GET path=/assets/foundation/orbit/left-arrow-5a8ccc07cfa3eae4292d7c705fc7b0a2.png host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=5ms connect=18ms service=32ms status=200 bytes=522
2013-02-01T20:17:18+00:00 heroku[router]: at=info method=GET path=/assets/foundation/orbit/right-arrow-6fca0c667c001b2352c44c9fb1e55528.png host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=2ms connect=7ms service=7ms status=200 bytes=3242
2013-02-01T20:31:22+00:00 heroku[router]: at=info method=GET path=/assets/application-6cd756f9981b294d6c6bd575ae87f94b.css host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=0ms connect=59ms service=15ms status=304 bytes=0
2013-02-01T20:31:22+00:00 heroku[router]: at=info method=GET path=/assets/orbit_05-c6ea9ca2a7468ee90a6c8bfc87eb607e.jpg host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=0ms connect=0ms service=1ms status=304 bytes=0
2013-02-01T20:31:22+00:00 heroku[router]: at=info method=GET path=/assets/orbit_03-42632d5ec29efd0b5e4c8cae7336e47c.jpg host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=0ms connect=0ms service=1ms status=304 bytes=0
2013-02-01T20:31:22+00:00 heroku[router]: at=info method=GET path=/assets/orbit_02-64cae3654d21289ce3fe325715c395ed.jpg host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=0ms connect=2ms service=3ms status=304 bytes=0
2013-02-01T20:31:29+00:00 heroku[router]: at=info method=POST path=/blurbs/1 host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=0ms connect=7ms service=167ms status=500 bytes=643
2013-02-01T20:31:22+00:00 heroku[router]: at=info method=GET path=/assets/application-ca9f839e91c53f606b8c9344a4a1243e.js host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=0ms connect=0ms service=1ms status=304 bytes=0
2013-02-01T20:31:22+00:00 heroku[router]: at=info method=GET path=/ host=exposehair-staging.herokuapp.com fwd=68.230.151.152 dyno=web.1 queue=0 wait=8ms connect=16ms service=148ms status=200 bytes=30683

还有我的gemfile

source 'https://rubygems.org'
ruby '1.9.3'

# Gems required by all environments
gem 'jquery-rails'
gem 'rails', '3.2.9'

gem 'acts-as-taggable-on'                     # https://github.com/mbleigh/acts-as-taggable-on
gem 'carrierwave'                             # https://github.com/jnicklas/carrierwave
gem 'combined_time_select', '~> 1.0.0'        # https://github.com/excid3/combined_time_select
gem 'fog', '~> 1.3.1'                         # https://github.com/fog/fog
gem 'font_awesome', '~> 3.0'                                # https://github.com/balexand/font_awesome
gem 'foundation_rails_helper',                  # https://github.com/sgruhier/foundation_rails_helper
  :git => 'git://github.com/sgruhier/foundation_rails_helper.git',
  :branch => 'master'
gem 'mini_magick'                             # https://github.com/probablycorey/mini_magick
gem 'rack-canonical-host'                     # https://github.com/tylerhunt/rack-canonical-host
gem 'redcarpet'                               # https://github.com/vmg/redcarpet
gem 'roboto'                                  # https://github.com/LaunchWare/roboto
gem 'slim-rails'                              # https://github.com/leogalmeida/slim-rails
gem 'sorcery'                                 # https://github.com/NoamB/sorcery
gem 'stamp'                                   # https://github.com/jeremyw/stamp
gem 'validates_email_format_of'               # https://github.com/alexdunae/validates_email_format_of

# Gems requred only for development
group :development, :test do
  gem 'better_errors'                         # https://github.com/charliesome/better_errors
  gem 'binding_of_caller'                     # optional dependancy of better_errors
  gem 'sqlite3'
end

# Gems required for heroku
group :staging, :production do
  gem 'foreman'
  gem 'pg'
  gem 'thin'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'coffee-rails', '~> 3.2.1'
  gem 'sass-rails',   '~> 3.2.3'
  gem 'uglifier', '>= 1.0.3'

  gem 'compass-rails'                                         # https://github.com/Compass/compass-rails
  gem 'zurb-foundation'                                   # http://foundation.zurb.com/docs/
end

我的 application.rb 文件中也有以下设置:

config.assets.initialize_on_precompile = false

更新:这是要求的一些相关代码。Heroku 上没有呈现任何 js 模板,但它们完全可以在本地工作。这就是我最初省略它的原因。

一个例子:

控制器/blurbs.rb

class BlurbsController < ApplicationController
  before_filter :require_login

  # PUT /blurbs/1
  def update
    @blurb = Blurb.find(params[:id])

    respond_to do |format|
      if @blurb.update_attributes(params[:blurb])
        format.js { }
      else
        format.js { render 'reload' }
      end
    end
  end
end

意见/模糊/reload.js

# Reload form
$("#editBlurb<%= @blurb.id %> form").html("<%= escape_javascript(render :partial => 'form', :locals => {:blurb => @blurb}) %>")

意见/模糊/_form.html.slim

= form_for blurb, remote: true do |f|
  .field
    = f.text_area :content, :label => blurb.name.titleize
  .actions = f.submit 'Save'
4

1 回答 1

4

我把日志级别转为调试

# staging.rb
config.log_level = :debug

并注意到以下内容:

Started PUT "/blurbs/1" for 68.230.151.152 at 2013-02-11 00:26:26 +0000
2013-02-11T00:26:26+00:00 app[web.1]: Processing by BlurbsController#update as JS
2013-02-11T00:26:26+00:00 app[web.1]:   Parameters: {"utf8"=>"✓", "authenticity_token"=>"rXyxUFU5qhjR4YieynLVAnr5ADnaUXn+No4Qruw5CFo=", "blurb"=>{"content"=>"# About us\r\n\r\nTell **your story** here."}, "commit"=>"Save", "id"=>"1"}
2013-02-11T00:26:26+00:00 app[web.1]: Completed 500 Internal Server Error in 318ms
2013-02-11T00:26:26+00:00 app[web.1]: 
2013-02-11T00:26:26+00:00 app[web.1]: ActionView::MissingTemplate (Missing template blurbs/update, application/update with {:locale=>[:en], :formats=>[:js, :html], :handlers=>[:erb, :builder, :slim]}. Searched in:
2013-02-11T00:26:26+00:00 app[web.1]:   * "/app/app/views"
2013-02-11T00:26:26+00:00 app[web.1]:   * "/app/vendor/bundle/ruby/1.9.1/gems/roboto-0.1.0/app/views"
2013-02-11T00:26:26+00:00 app[web.1]: ):

Heroku 上的 Rails 只在寻找 js、html、erb、builder 或 slim。不是咖啡脚本。然后我记得咖啡脚本在我的 gemfile 的资产组中。它在 heroku 上进行了预处理,但是 gem 不能与应用程序一起运行。所以我将 gem 移到资产组之外,我的应用现在可以在 Heroku 上完美运行!

由于@Dominic 的回答将我带到了那里,如果您想索取我为解决我的问题而提供的 10 美元,请通过您的贝宝与我联系。对此,我真的非常感激。谢谢你。

https://stackoverflow.com/users/1704688/keil-miller

于 2013-02-11T00:46:55.303 回答