6

I'm having some problems with Rails 3 and HAML in my application: for some reason Rails appears not to be loading the handler for dealing with haml files. Every action gives an error message similar to this one:


Template is missing

Missing template contact_search/index with {:formats=>[:html], :handlers=>[:rjs, :rhtml, :rxml, :builder, :erb], :locale=>[:en, :en]} in view paths "/var/www/osphonebook/app/views", "/var/www/osphonebook/vendor/bundle/ruby/1.8/gems/devise-1.3.4/app/views"


Look at the "handlers" options: it does not have :haml...

The thing is that this only happens during production mode on the server set up by my company. On development and test modes it works fine. Also, if I start the application in production mode on my development PC, it works.

Some info about the server:

UPDATE (6/6/2011): upgraded to Ruby 1.9, and it still does not work.

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)

If more info is needed, please comment the question, and I'll update it. Thanks for any help.

ldnunes
  • 178
  • 3
  • 14
  • For the error you posted, what is the exact filename of your view template? – Dylan Markow Jun 03 '11 at 14:06
  • 1
    Also, did you update your bundle and restart the server on your production machine? – Dylan Markow Jun 03 '11 at 14:09
  • @dmarkow Thank you for the comments. The file name is app/views/contact_search/index.html.haml And yes, the server was restarted after the bundle. – ldnunes Jun 03 '11 at 14:16
  • 2
    **Do not put haml in the :assets group.** Gems in the asset group aren't included in production by default. *I know you've already found a solution, I'm just hoping to stop someone falling into the same trap as me.* – Zaz Apr 03 '13 at 19:16
  • Similarly, don't just put haml-rails in the :development Gemfile group, I was running automated tests so I needed to include haml-rails in :test as well. – Han May 10 '13 at 04:37

4 Answers4

5

Try with the gem haml-rails

Michaël Witrant
  • 7,525
  • 40
  • 44
  • I've seen people use both gem 'haml' and gem 'haml-rails' with success. I think they're the same, but the official docs say to use gem 'haml'. – Trent Scott Jun 03 '11 at 18:38
  • 2
    They're not the same. Haml-rails provides generators and activates HAML in Rails. It should work without it, but using it may be a quick fix for his problem. – Michaël Witrant Jun 03 '11 at 18:49
  • 1
    Thank you for the suggestion, I just tried it, but unfortunately it didn't work. The "template is missing" error still continues. @Trenton From what I have seen from the source on GitHub, haml-rails adds generators and set some basic options for the real haml gem. – ldnunes Jun 03 '11 at 18:51
  • AFTER A WHOLE DAY OF RE-WRITING PORTIONS OF CODE, 20 DIFFERENT WAYS TRYING ALL SORTS - This resolved my issue on Heroku! Something I could not reproduce locally --- THANKYOU Michaël – Spasm Jun 08 '12 at 05:03
5

I've found the problem: I had changed the config/environments/production.rb file to set some personalized code for the ActionMailer. The thing is that I was using the class directly, like this:

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

instead of doing like this:

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

It appears that using the ActionMailer class directly fired the ActionView loaders, and set all the internal variables, preventing the HAML code to install itself.

After changing the code it worked like a charm.

ldnunes
  • 178
  • 3
  • 14
  • @Sam I saw somwhere that the new "config.action_mailer" sintax is prefered to the old one, with sets the config directly in the class. But after trying so many things to get it to work, it was mostly luck and desperation... – ldnunes Mar 21 '12 at 15:00
2

I found the solution to the 'missing HAML template' error when running in production mode (using Rails 3.2.6 and haml-rails 0.3.4):

In /config/application.rb it has

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

I changed this to

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

And now it works.

BryanH
  • 5,826
  • 3
  • 34
  • 47
Joseph Ramos
  • 196
  • 2
  • 13
  • Thanks for the tip. I had the problem in an engine developing with using a dummy app, and had the haml gem in a group in the Gemfile. I changed `Bundler.require` to `Bundler.require(:default, Rails.env, :dummy_app)` and this solved it. – Leventix Aug 13 '13 at 12:21
0

Does adding

require "haml"

to config/test.rb (and/or development.rb and production.rb) fix this for you?

(Note that I'm using Rails 3.2.2)

BryanH
  • 5,826
  • 3
  • 34
  • 47
mcmSEA
  • 191
  • 1
  • 1
  • 11