2010-09-25 78 views
21

我試圖在Rails 3中使用HAML渲染一些文件但沒有成功。HAML on Rails 3返回「模板丟失」錯誤

我的測試文件的擴展名爲.html.haml

在我的Gemfile中,我有行gem 'haml'並已運行bundle install

當我運行我的應用程序,我得到以下錯誤:

Template is missing

Missing template posts/index with {:locale=>[:en, :en], :formats=>[:html], :handlers=>[:rjs, :rhtml, :rxml, :builder, :erb]} in view paths "/Users/piet/Sites/blog/app/views"`

關於如何解決這個任何想法?

+1

你有沒有重新啓動你的導軌進程? – 2010-09-25 20:33:41

+0

我將'yourview.html.erb'重命名爲'yourview.html.haml',並顯示'Template is Missing'。所以我重新啓動了Rails服務器,現在它正在工作。 – Bao 2014-02-10 17:13:04

回答

1

HAML不工作沒有問題的Rails 3 ..兩件事情:

  1. 確保你的路線文件有resources :posts
  2. 請確保您有該文件的應用程序/視圖/職位/ index.html.haml

你可以試試嗎?並確認安德魯關於重新啓動Rails的評論也已被嘗試。

+0

我不知道爲什麼,但現在它的工作; 9 Thx爲您的答案 – Peter 2010-09-25 22:28:42

69

爲Rails 3,所有你需要做的就是添加:

寶石 「HAML護欄」

您的Gemfile,然後做一個 「包安裝」

https://github.com/indirect/haml-rails

如果您仍然看到錯誤,請嘗試重新啓動服務器。

+15

這應該被標記爲答案 - 重新啓動服務器是我需要的額外步驟。 – Milktrader 2011-05-13 15:26:19

+1

+1將此標記爲答案 – 2011-05-25 20:10:30

+0

我還需要重新啓動服務器。 +1這個答案。 – 2012-11-24 04:10:40

2

如果從Rails的升級2到Rails 3中,確保這是靠近你config/application.rb文件的頂部:

# If you have a Gemfile, require the gems listed there, including any gems 
# you've limited to :test, :development, or :production. 
Bundler.require(:default, Rails.env) if defined?(Bundler) 

應該是正確的下面

# Put this in config/application.rb 
require File.expand_path('../boot', __FILE__) 
require 'rails/all' 
+0

我一直以來都認爲自己有一種rvm/passenger/gemsets/unix權限問題,因爲這個原因,我整天都在一隻兔子洞裏。在Capifying和部署到新服務器時,我添加了一個新環境('qa')。整個時間我需要添加'qa'到以下行Bundler.require(* Rails.groups(:assets =>%w(qa development test)))''。感謝您指引我朝着正確的方向發展。確認, – Chris 2012-02-22 22:00:04

+0

,我的問題完全一樣 – 2012-03-21 03:09:59