haml / haml-rails

let your Gemfile do the talking
MIT License
1.04k stars 169 forks source link

Problem with Haml::Rails::Generators when upgrading from haml_rails #142

Open JohnSmall opened 6 years ago

JohnSmall commented 6 years ago

Took a while to sort this out, so it would be nice to add something to the read me.

In a Rails 5.2 project I previously had just

gem 'haml_rails'

in my Gemfile, it was happily generating haml for new views. But I didn't have the erb to haml converter so I upgraded to

gem "haml-rails", "~> 1.0"

Which provided the utililty to convert my application layout to haml. But it also completely busted view generation so that when I scaffold a new model I now get this error

Could not load generator "generators/haml/scaffold/scaffold_generator". Error: uninitialized constant 
Haml::Rails::Generators.

I commented out the line in config/application.rb

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

which was there before when I was just using gem 'haml_rails' as the newer gem "haml-rails", "~> 1.0" shouldn't need it (that's the main point of the updated gem). But was still broken.

Finally after a lot of head scratching and wasted time I realised that haml-rails might not be a direct descendent of haml_rails and simply doesn't upgrade cleanly. So I had to remove 'haml_rails' from my installed gems and remove the lib/generators directory which had haml templates and generators in it.

It now works, but.. that lib/generators was incredibly useful because it had templates I could edit to get new views as I wanted them. e.g form_with or boostrap_form_with.

It would be nice to take the code for templates from haml_rails, an old dead project, and use it in haml-rails so that users could have editable templates.