2

I'm developing a Rails 3.1 engine, and to integration test it I want to use SLIM instead of plain ol' ERB. So I tried to simply add s.add_development_dependency "slim" to my .gemspec file, but when renaming my index.html.erb file to index.html.slim, Rails complains:

Missing template dummy/index, application/index with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder]}. Searched in: * "/Users/josh/Documents/Work/Sientia/iq_menu/full/spec/dummy/app/views" * "/Users/josh/Documents/Work/Sientia/iq_menu/full/app/views"

I tried it also with the slim-rails gem and also with the haml-rails gem, but there renaming the file to index.html.haml resulted in the same error.

What am I doing wrong?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Joshua Muheim
  • 12,617
  • 9
  • 76
  • 152

3 Answers3

4

Obviously, this is an old problem, but I ran into the same thing today (this time on Rails 4), and I think I can clarify the problem, here.

Bundler serves two roles -- one is to fetch the gems and make their code available, the other is to actually "require" that code into your project.

When you add a dependency into your gemspec, it does the first function, but not the second.

In production use of your application, the dependencies identified by your gemspec are effectively added to the application's bundle, so the application's bundler will both fetch and require your gems.

If you only have the reference in the gemspec, and not in your Gemfile, then effectively nothing is doing the require, so the gem doesn't get initialized and the template engine isn't made available to your application. Adding it to the Gemfile makes it get initialized and registered.

I think you need both, for something like slim/haml. Just having the Gemfile reference means the application won't know about the dependency, and just having the gemspec reference means the engine doesn't get initialized in your dummy app.

scottb
  • 1,135
  • 11
  • 17
3

You can use the standard haml gem, but in your engine.rb you need to have:

require 'haml'

iHiD
  • 2,450
  • 20
  • 32
2

For Haml you have to put

gem 'haml-rails'

into your Gemfile

Flo
  • 540
  • 6
  • 20
  • Thank you, this works. Still, I'm a bit confused: in Yehuda Katz' Post [Clarifying the Roles of the .gemspec and Gemfile](http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/) he mentions that when developing a gem, the Gemfile "a gem’s Gemfile should contain the Rubygems source and a single gemspec line". Why's it different here? – Joshua Muheim Sep 20 '12 at 09:01
  • Sorry, but I don't understand your question. Do you want to develop a gem? Or just use the haml gem? For just using HAML you only need the haml-rails gem and not haml and haml-rails – Flo Sep 20 '12 at 09:14
  • I'm developing a gem using Rails 3.1's `rails plugin new my_engine` command. – Joshua Muheim Sep 21 '12 at 05:58