如何修复Rails 3中丢失的模板?

时间:2014-05-10 00:27:34

标签: ruby-on-rails ruby ruby-on-rails-3

我想知道如何解决以下错误。

我的代码:

控制器/ application_controller.rb

class ApplicationController < ActionController::Base
  def home
    @app_name = Cache.app_name
    respond_to do |format|
      format.html {render "application/home"}
    end
  end

视图/应用/ home.html.erb

<h1>Home</h1>

错误:

Missing template application/home with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :arb, :rabl]}. Searched in: * "/srv/www/intel/releases/20140509010259/app/views" * "/home/deploy/.bundler/intel/ruby/1.9.1/gems/ckeditor-4.0.11/app/views" * "/home/deploy/.bundler/intel/ruby/1.9.1/bundler/gems/active_admin-b41450a52c09/app/views" * "/home/deploy/.bundler/intel/ruby/1.9.1/gems/kaminari-0.15.1/app/views" * "/home/deploy/.bundler/intel/ruby/1.9.1/gems/devise-3.2.4/app/views"

BACKTRACE:
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_view/path_set.rb:58:in `find'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_view/lookup_context.rb:122:in `find'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_view/renderer/abstract_renderer.rb:3:in `find_template'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_view/renderer/template_renderer.rb:34:in `determine_template'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/newrelic_rpm-3.8.0.218/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:157:in `render_with_newrelic'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_view/renderer/renderer.rb:36:in `render_template'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_view/renderer/renderer.rb:17:in `render'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:110:in `_render_template'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/streaming.rb:225:in `_render_template'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:103:in `render_to_body'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/renderers.rb:28:in `render_to_body'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/compatibility.rb:50:in `render_to_body'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:88:in `render'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/rendering.rb:16:in `render'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:40:in `block (2 levels) in render'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/core_ext/benchmark.rb:5:in `block in ms'
/usr/local/lib/ruby/1.9.1/benchmark.rb:295:in `realtime'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/core_ext/benchmark.rb:5:in `ms'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:40:in `block in render'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:83:in `cleanup_view_runtime'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/railties/controller_runtime.rb:24:in `cleanup_view_runtime'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:39:in `render'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/implicit_render.rb:10:in `default_render'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/implicit_render.rb:5:in `send_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/base.rb:167:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/rendering.rb:10:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:447:in `_run__2038047062599410293__process_action__4203207241704581942__callbacks'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/callbacks.rb:17:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/rescue.rb:29:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123:in `block in instrument'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/notifications.rb:123:in `instrument'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/newrelic_rpm-3.8.0.218/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:38:in `block in process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/newrelic_rpm-3.8.0.218/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:336:in `perform_action_with_newrelic_trace'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/newrelic_rpm-3.8.0.218/lib/new_relic/agent/instrumentation/rails3/action_controller.rb:37:in `process_action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/base.rb:121:in `process'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/abstract_controller/rendering.rb:45:in `process'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal.rb:203:in `dispatch'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_controller/metal.rb:246:in `block in action'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:73:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:36:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/routing/route_set.rb:608:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:186:in `call!'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/omniauth-1.2.1/lib/omniauth/strategy.rb:164:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/omniauth-1.2.1/lib/omniauth/builder.rb:59:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/newrelic_rpm-3.8.0.218/lib/new_relic/rack/error_collector.rb:55:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/newrelic_rpm-3.8.0.218/lib/new_relic/rack/agent_hooks.rb:32:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/newrelic_rpm-3.8.0.218/lib/new_relic/rack/browser_monitoring.rb:27:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/deflater.rb:13:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/head.rb:14:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/flash.rb:242:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/cookies.rb:341:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/query_cache.rb:64:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405:in `_run__3093961360070573583__call__3302946055201972876__callbacks'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/railties-3.2.18/lib/rails/rack/logger.rb:32:in `call_app'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/railties-3.2.18/lib/rails/rack/logger.rb:16:in `block in call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/tagged_logging.rb:22:in `tagged'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/railties-3.2.18/lib/rails/rack/logger.rb:16:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/request_id.rb:22:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/activesupport-3.2.18/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/actionpack-3.2.18/lib/action_dispatch/middleware/static.rb:63:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:245:in `fetch'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:185:in `lookup'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:66:in `call!'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-timeout-0.0.4/lib/rack/timeout.rb:16:in `block in call'
/usr/local/lib/ruby/1.9.1/timeout.rb:69:in `timeout'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/rack-timeout-0.0.4/lib/rack/timeout.rb:16:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/railties-3.2.18/lib/rails/engine.rb:484:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/railties-3.2.18/lib/rails/application.rb:231:in `call'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/railties-3.2.18/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:572:in `process_client'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:666:in `worker_loop'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:521:in `spawn_missing_workers'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:140:in `start'
/home/deploy/.bundler/intel/ruby/1.9.1/gems/unicorn-4.8.2/bin/unicorn_rails:209:in `'
/home/deploy/.bundler/intel/ruby/1.9.1/bin/unicorn_rails:23:in `load'
/home/deploy/.bundler/intel/ruby/1.9.1/bin/unicorn_rails:23:in `'

2 个答案:

答案 0 :(得分:2)

提示:您不应将公开方法放入application_controller。有一个额外的控制器,并检查您的routes.rb和查看文件名称:

# in app/controllers/home_controller.rb
class HomeController < ApplicationController
  def index
    @app_name = Cache.app_name
  end
end

# in app/views/home/index.html.erb
<h1>Home of <%= @app_name %></h1>

# in config/routes.rb
root to: 'home#index'

答案 1 :(得分:0)

您可以使用rails生成器创建一个新的控制器来放置它。不要使用应用程序控制器。

例如:     rails g controller home index

这将创建一个Home控制器和一个索引操作以及所需的默认文件。它还将为您创建路线和资产。