Rails 3没有加载HAML处理程序

时间:2011-06-03 13:50:10

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

我的应用程序中存在Rails 3和HAML的一些问题:由于某种原因,Rails似乎没有加载处理haml文件的处理程序。每个操作都会显示与此类似的错误消息:


缺少模板

缺少模板contact_search / index with {:formats =&gt; [:html],:handlers =&gt; [:rjs,:rhtml,:rxml,:builder,:erb],:locale =&gt; [:zh ,:en]}在视图路径“/ var / www / osphonebook / app / views”,“/ var / www / osphonebook / vendor / bundle / ruby​​ / 1.8 / gems / devise 1.3.4 / app / views”< / p>


查看“处理程序”选项:它没有:haml ...

事情是,这只发生在我公司设置的服务器上的生产模式中。在开发和测试模式下,它工作正常。此外,如果我在开发PC上以生产模式启动应用程序,它就可以工作。

有关服务器的一些信息:

更新(2011年6月6日):已升级到Ruby 1.9 ,但仍无效。

ruby 1.9.2p0 (2010-08-18 revision 29036) [i486-linux]

Gems included by the bundle:
abstract (1.0.0)
actionmailer (3.0.7)
actionpack (3.0.7)
activemodel (3.0.7)
activerecord (3.0.7)
activeresource (3.0.7)
activesupport (3.0.7)
arel (2.0.10)
bcrypt-ruby (2.1.4)
builder (2.1.2)
bundler (1.0.14)
devise (1.3.4)
erubis (2.6.6)
haml (3.1.1)
i18n (0.5.0)
kgio (2.4.1)
mail (2.2.19)
mime-types (1.16)
orm_adapter (0.0.5)
pg (0.11.0)
polyglot (0.3.1)
rack (1.2.3)
rack-mount (0.6.14)
rack-test (0.5.7)
rails (3.0.7)
railties (3.0.7)
rake (0.8.7)
sass (3.1.2)
sqlite3 (1.3.3)
thor (0.14.6)
treetop (1.4.9)
tzinfo (0.3.27)
unicorn (3.6.2)
warden (1.0.4)

如果需要更多信息,请对问题发表评论,我会更新。谢谢你的帮助。

4 个答案:

答案 0 :(得分:5)

尝试使用gem haml-rails

答案 1 :(得分:5)

我发现了问题:我更改了config/environments/production.rb文件,为ActionMailer设置了一些个性化代码。问题是我直接使用该类,如下所示:

ActionMailer::Base.delivery_method = :sendmail
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.charset = "utf-8"

而不是这样:

config.action_mailer.delivery_method = :sendmail
config.action_mailer.raise_delivery_errors = true
config.action_mailer.charset = "utf-8"

似乎使用ActionMailer类直接触发ActionView加载器,并设置所有内部变量,阻止HAML代码自行安装。

更改代码后,它就像魅力一样。

答案 2 :(得分:2)

在生产模式下运行时,我找到了“缺少HAML模板”错误的解决方案 (使用Rails 3.2.6和haml-rails 0.3.4):

/config/application.rb中有

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

我将此更改为

if defined?(Bundler)
  # If you precompile assets before deploying to production, use this line
  # Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  Bundler.require(:default, :assets, Rails.env)
end

现在它有效。

答案 3 :(得分:0)

添加

require "haml"

config/test.rb(和/或development.rbproduction.rb)为您解决此问题?

(请注意,我使用的是Rails 3.2.2)

相关问题