Theo Scholiadis
Theo Scholiadis

Reputation: 2396

Haml-rails not working in Rails 3 Engine

I have created a Rails Engine (as per the Rails Guides) using:

rails plugin new address_book --full --mountable

I then proceeded to follow the instructions in the answer to this question, trying both the "haml" gem, as well as the "haml-rails" gem (I would like the latter, as I use it in my parent application too).

For some reason, after running bundle, and then

rails g controller pages temp

it still creates the .erb files instead of the .haml files.

Any assistance would be appreciated. My code is as follows:

The 'lib/address_book.rb' file:

require "address_book/engine"
require "haml-rails"

module AddressBook
end

The 'address_book.gemspec' file:

$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "address_book/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
  s.name        = "address_book"
  s.version     = AddressBook::VERSION
  s.authors     = ["TODO: Your name"]
  s.email       = ["TODO: Your email"]
  s.homepage    = "TODO"
  s.summary     = "TODO: Summary of AddressBook."
  s.description = "TODO: Description of AddressBook."

  s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"]
  s.test_files = Dir["test/**/*"]

  s.add_dependency "rails", "~> 3.2.5"
  s.add_dependency "haml-rails"
  # s.add_dependency "jquery-rails"

  s.add_development_dependency "sqlite3"
end

The 'Gemfile' file:

source "http://rubygems.org"

gemspec

gem "jquery-rails"

Upvotes: 1

Views: 913

Answers (2)

E.FU
E.FU

Reputation: 400

try this:

Add to your gem spec:

s.add_dependency 'haml-rails'

than go over to your engine.rb file and add:

config.generators do |g| 
  g.template_engine :haml
end

last step: Add to the Engines Gemspec:

gem 'haml-rails'

Your generators will now produce the haml views.

Upvotes: 2

phoet
phoet

Reputation: 18845

in a normal application you would configure this in the app-config in application.rb like:

config.generators do |g|
  g.template_engine :haml
end

i don't know if it's possible to add such a file to an engine. it might be possible to configure it through a railtie-config-hook.

despite these configuration options, you should be able to specify the template-engine directly in your commandline:

rails g controller pages temp -e=haml

Upvotes: 1

Related Questions