Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm developing a Rails3 engine application, and I want to use Haml for the views.

First, what I have done was to add this to the engine Gemfile:

gem "haml"

While I was testing my engine, it was working OK (I have used https://github.com/josevalim/enginex to generate the gem and test it with the dummy application).

My problems started when I tried to use the engine on a real Rails application. The application does not have gem "haml" on it's own Gemfile, and so it was not initializing Haml, so I was receiving template not found errors as it was not looking for the .haml views. I was thinking that by requiring Haml on the Engine it would be enought for it to be also required by the Rails application.

What I have done for now was to add a config/initializers/haml.rb on the engine with this code:

require 'haml'
Haml.init_rails(binding)

It's working now, but I'm wondering if this is really a good way to do it. Why Rails is not calling Haml "init.rb" file and so initializing Haml correctly by just adding gem "haml" to the engine Gemfile?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
657 views
Welcome To Ask or Share your Answers For Others

1 Answer

Two things are necessary. First, in the .gemspec:

s.add_dependency 'haml', ['>= 3.0.0']

And in your lib/gem_name.rb:

require 'haml'

And then run bundle both inside the gem and app directories.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...