我有一个Rails应用程序,在我的开发机器上工作得很好,但是当我将它部署到Heroku时,我在部署后尝试加载页面时收到以下错误消息。
ActionView::Template::Error (undefined method `call' for :silence:Symbol):
31: <div id="tickets">
32: <div id="subline">Tickets open for trading</div>
33: <% if not @tickets.blank? %>
34: <%= render( :partial => '/choices/choice.html.erb', :locals => { :choice => @tickets} ) %>
35: <% end %>
36: </div>
app/views/home/index.html.erb:34:in `_app_views_home_index_html_erb___4151329774010405498_38984040'
app/controllers/home_controller.rb:108:in `index'
我似乎无法弄清楚出了什么问题,因为它在我自己的机器上工作正常,所以任何帮助都会非常适合:)
编辑1:
这是我的家庭控制器的一部分,与上述相关..
class HomeController < ApplicationController
def index
@tickets = Choice.betable(current_user).where("choices.created_at > ?", Time.at(params[:after].to_i + 1).utc).order("choices.created_at DESC")
respond_to do |format|
format.html
format.json do
@html_choice = render_to_string( :partial => '/choices/choice.html.erb', :locals => { :choice => @tickets} )
@html_active_choices = render_to_string( :partial => '/shared/active_choices.html.erb', :locals => { :active_choices => @active_choices} )
@html_active_bets = render_to_string( :partial => '/shared/active_bets.html.erb', :locals => { :active_bets => @active_bets} )
@html_spotprices_today = render_to_string( :partial => '/shared/spotprices_today.html.erb', :locals => { :spotprices_today => @spotprices_today} )
render :json => { :success => true, :html_choice => @html_choice, :html_active_choices => @html_active_choices, :html_active_bets => @html_active_bets, :html_spotprices_today => @html_spotprices_today }
end
end
end
end
json响应是[Pusher] [1]使用websocket将更新数据推送到网站。
在下面找到日志文件:
2012-11-12T06:04:20+00:00 app[web.1]: => Booting Thin
2012-11-12T06:04:20+00:00 app[web.1]: => Rails 3.2.8 application starting in production on http://0.0.0.0:40112
2012-11-12T06:04:20+00:00 app[web.1]: => Call with -d to detach
2012-11-12T06:04:20+00:00 app[web.1]: => Ctrl-C to shutdown server
2012-11-12T06:04:20+00:00 app[web.1]: >> Thin web server (v1.3.1 codename Triple Espresso)
2012-11-12T06:04:20+00:00 app[web.1]: >> Maximum connections set to 1024
2012-11-12T06:04:20+00:00 app[web.1]: >> Listening on 0.0.0.0:40112, CTRL+C to stop
2012-11-12T06:04:24+00:00 app[web.1]:
2012-11-12T06:04:24+00:00 app[web.1]:
2012-11-12T06:04:24+00:00 app[web.1]: Started GET "/rails/info/properties" for 157.55.34.32 at 2012-11-12 06:04:24 +0000
2012-11-12T06:04:24+00:00 heroku[router]: GET mydomain.com/rails/info/properties dyno=web.1 queue=0 wait=0ms service=51ms status=404 bytes=728
2012-11-12T06:04:24+00:00 heroku[nginx]: 157.55.34.32 - - [12/Nov/2012:06:04:24 +0000] "GET /rails/info/properties HTTP/1.1" 404 728 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)" mydomain.com
2012-11-12T06:04:24+00:00 app[web.1]:
2012-11-12T06:04:24+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/rails/info/properties"):
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/rack/logger.rb:26:in `call_app'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/rack/logger.rb:16:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/request_id.rb:22:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.8/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/engine.rb:479:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.8/lib/action_dispatch/middleware/static.rb:62:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/application.rb:223:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/content_length.rb:14:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/rack/log_tailer.rb:17:in `call'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:53:in `process'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:38:in `receive_data'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:55:in `block in <top (required)>'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:265:in `start'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands/server.rb:70:in `start'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
2012-11-12T06:04:24+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
2012-11-12T06:04:24+00:00 app[web.1]: script/rails:6:in `require'
2012-11-12T06:04:24+00:00 app[web.1]: script/rails:6:in `<main>'
2012-11-12T06:04:24+00:00 app[web.1]:
2012-11-12T06:04:24+00:00 app[web.1]:
2012-11-12T08:56:34+00:00 heroku[router]: GET www.mydomain.com/ dyno=web.1 queue=0 wait=0ms service=607ms status=500 bytes=643
2012-11-12T08:56:34+00:00 heroku[nginx]: 87.60.190.9 - - [12/Nov/2012:08:56:34 +0000] "GET / HTTP/1.1" 500 643 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:14.0) Gecko/20100101 Firefox/14.0.1" www.mydomain.com
希望这有助于找到导致错误的原因:)
谢谢!
答案 0 :(得分:2)
尝试更改:
... :partial => '/choices/choice.html.erb'
于:
... :partial => '/choices/choice'
在您的视图和控制器中。为了帮助您更清楚,请查看Using Partial。
答案 1 :(得分:0)
我的网络应用程序中出现了同样明显误导性的错误,仅在生产环境中引发但是在开发过程中一切正常。
我的日志如下:
NoMethodError (undefined method `call' for :silence:Symbol):
app/controllers/users_controller.rb:77:in `block in XXX'
app/controllers/users_controller.rb:77:in `each'
app/controllers/users_controller.rb:77:in `XXX'
app/controllers/users_controller.rb:32:in `YYY'
app/controllers/application_controller.rb:46:in `ZZZ'
请注意,调试器指出的上下文完全不同。由于此错误仅在生产环境中出现,我认为它可能不是由某些编码错误引起的。 所以我开始研究开发和生产设置之间的差异,并最终发现我添加了以下行以摆脱一些嘈杂的Heroku弃用警告:
config.active_support.deprecation = :silence
但由于“:沉默”符号尚未在DEFAULT_BEHAVIORS [:沉默]中定义,(检查https://github.com/rails/rails/pull/5986),因此导致了问题。 既然你也说你正在使用Heroku,那么请你检查一下这是否也是你错误的原因?
答案 2 :(得分:0)
必须:
设置 formats
和 handlers
示例强>:
@html_choice = render_to_string( \
partial: '/choices/choice', \
formats: [:html], handlers: [:erb], \
locals: {choice: @tickets})