haml / haml-rails

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

Rails 5.0.1 Missing template when adding haml-rails to a rails engine #124

Open AndyCapiau opened 7 years ago

AndyCapiau commented 7 years ago

In _engine_name/enginename.gemspec, I added: s.add_dependency "haml-rails"

In _engine_name/lib/enginename.rb, I added: require "haml-rails"

In _engine_name/lib/enginename/engine.rb, I added:

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

I ran the 'bundle' command both in:

When going to the test/dummy directory and (re)start the rails server, when I then go to "localhost/engine_name/resource" I get a template missing.

The very same way of working, works fine in rails 4.2.8

jakeonrails commented 6 years ago

I came here to report this same issue.

Adding haml-rails to the project that includes your Rails engine/plugin makes the problem go away, but I thought that adding haml-rails as a dependency would Just Work™.

Btw, I'm on Rails 5.1.x (and same version for the engine).

krisleech commented 6 years ago

I get an error such as:

 Missing partial screening/studies/_show with {:locale=>[:en], :formats=>[:js, :html,  <snip>], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}.

Notice not haml in the handlers. Is this the same error you get?

I have haml-rails in Gemfile and require it in the engines ApplicationController.

krisleech commented 6 years ago

My solution, as per this comment, was to add require "haml" to lib/<PROJECT>/engine.rb.

topherfangio commented 4 years ago

Just ran into this with 5.2.3 and can confirm that adding require "haml" to my engine file fixed the issue. Thanks!

nickpearson commented 2 years ago

Adding require 'haml' to my engine file fixed the ActionView::MissingTemplate: Missing partial issue for me as well in Rails 5.2 three years ago, but the problem resurfaced when upgrading to Rails 7 (not sure about 6 and 6.1) when using render_to_string to render a partial inside an engine controller.

I found a commit in the kaminari gem that fixes seemingly the same issue by specifying the rendering format:

# this fails when called from an engine controller in Rails 7:
render_to_string(partial: 'table')

# specifying :html as a format makes it work:
render_to_string(partial: 'table', formats: [:html])