2010-01-01 216 views
6

UPDATE:隨意給我投了反對票,因爲這個問題是我當時命名的文件_stylesheet.html.erb &不_stylesheets.html。 ERB。我以爲我檢查拼寫,但很明顯我沒有。我很抱歉浪費大家的時間,我感謝你的意見。問題渲染*非常*簡單部分在* *非常簡單的應用程序

嗨,

我學習軌和我開始Ruby on Rails Tutorial - Learn Rails by Example by Michael Hartl。這是一本他正在慷慨地上網的書。我目前在partials section,我看到一個奇怪的問題,我昨天一直試圖解決。我按照諧音部分的說明,但我收到以下錯誤:

ActionView::MissingTemplate in Pages#home 

Showing app/views/layouts/application.html.erb where line #6 raised: 

Missing layout layouts/_stylesheets.erb in view path app/views 
Extracted source (around line #6): 

3: <html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml"> 
4: <head> 
5:  <title><%= title %></title> 
6:  <%= render 'layouts/stylesheets' %> 
7: </head> 
8: <body> 
9:  <div class="container"> 

這裏是跟蹤:

/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/paths.rb:66:in `find_template' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/partials.rb:236:in `_unmemoized__pick_partial_template' 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/memoizable.rb:84:in `_pick_partial_template' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/partials.rb:184:in `render_partial' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:276:in `render' 
/media/documents/Dropbox/Projects/rails/sample_app/app/views/layouts/application.html.erb:6:in `_run_erb_app47views47layouts47application46html46erb' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:34:in `send' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:34:in `render' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:306:in `with_template' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:30:in `render' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/template.rb:205:in `render_template' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:265:in `render' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:352:in `_render_with_layout' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:262:in `render' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1250:in `render_for_file' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:945:in `render_without_benchmark' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:51:in `render' 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' 
/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime' 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:51:in `render' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1326:in `default_render' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1332:in `perform_action_without_filters' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:617:in `call_filters' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:610:in `perform_action_without_benchmark' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' 
/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime' 
/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/core_ext/benchmark.rb:17:in `ms' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:in `perform_action_without_flash' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/flash.rb:146:in `perform_action' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `send' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in `process_without_filters' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:in `process' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:391:in `process' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:87:in `dispatch' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:121:in `_call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:130:in `build_middleware_stack' 
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' 
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:29:in `call' 
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/query_cache.rb:34:in `cache' 
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:9:in `cache' 
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/query_cache.rb:28:in `call' 
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:361:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/string_coercion.rb:25:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/head.rb:9:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:24:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/params_parser.rb:15:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/session/cookie_store.rb:93:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/failsafe.rb:26:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:114:in `call' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:34:in `run' 
/usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call' 
/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/static.rb:31:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call' 
/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/log_tailer.rb:17:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/chunked.rb:15:in `call' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:64:in `process' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:159:in `process_client' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `each' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:158:in `process_client' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `initialize' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `new' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:285:in `run' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `initialize' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `new' 
/usr/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel.rb:268:in `run' 
/usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/mongrel.rb:34:in `run' 
/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111 
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require' 
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' 
script/server:3 

什麼讓我感興趣的是,我有本地的其他項目,成功地使諧音。所以我知道這不是一個rails版本問題(另一個工程沒有凍結rails)。我也檢查過我的部分是在app/views/layouts中,並且在他們的名字和擴展名正確順序(.html.erb)之前有一個下劃線。

這裏是控制器:

class PagesController < ApplicationController 
    def home 
    @title = "Home" 
    end 

    def contact 
    @title = "Contact" 
    end 

    def about 
    @title = "About" 
    end 

    def help 
    @title = "Help" 
    end 
end 

這是非常標準的東西,我不知道爲什麼它不工作是誠實的。對此事的任何幫助都非常感謝。

謝謝!

阿希什

回答

1

既然你想渲染一個部分,你的部分文件是否帶有下劃線的前綴?

_stylesheets.html.erb 
+0

@nowk - 是的。我檢查了第一個。我的部分名爲_stylesheets.html.erb,它位於app/views/layouts中。 – tundal45 2010-01-01 18:14:18

+0

嗯,只是爲了覆蓋所有的基地,你有沒有嘗試重新啓動你的應用程序?我最近在開發環境時遇到了一些問題,在2.3.5中沒有重新啓動的情況下沒有處理新的東西。 – nowk 2010-01-01 18:32:09

+0

@nowk - 我很抱歉沒有提到這之前,但我試過重新啓動服務器。我甚至重新啓動了我的電腦(窗口壞習慣),但沒有成功。 – tundal45 2010-01-01 19:04:29

3

我真的不知道什麼Rails的你正在使用的版本,但我建議下列之一:

  1. 添加:部分選項:<%= render :partial=>'layouts/stylesheets' %>(我相信這一個會爲工作你)
  2. 將文件stylesheets.html.erb重命名爲stylesheets.erb(我對這個不是很滿意,但它可能適用於你)。
+0

我覺得他使用的是2.3.5版本。看看他的日誌。我認爲:部分=>'佈局/樣式表'你提到的事情會爲這個人做伎倆。 – DJTripleThreat 2010-01-01 17:49:55

+0

@khelll - 感謝您的快速回復。我沒有提到我曾嘗試過顯式:partial =>調用,但沒有取得太大的成功。我也嘗試將文件重命名爲stylesheets.erb而不是stylesheets.html.erb,並且這種方式也不起作用。第二個不能正常工作,因爲這違反了導軌和其他可用的文件。 @DJTripleThreat正確。我正在使用rails 2.3.5版,並且正在運行ruby 1.8.7(2009-06-12 patchlevel 174)。我可以提供哪些額外的信息可能指出爲什麼會發生這種情況? – tundal45 2010-01-01 18:03:51

+0

@khell&@DJTripleThreat:我很抱歉浪費你的時間。我意識到我已經命名文件_stylesheet.html.erb&not _stylesheets.html.erb。菜鳥,我知道! – tundal45 2010-01-01 19:28:57