How to ignore file extention tilde(~) on template engine searching?


Dear all,

When a template file path is apps/web/templates/books/index.html.erb, some editor (e.g. emacs, jstar) generates backup file with tilde(~) as index.html.erb~ at the same directory.

Hanami server looks recognize *.erb~ also correspond to some engine, but finally it fails as follows:

Boot Error
Something went wrong while loading …bookshelf/
RuntimeError: No template engine registered for index.html.erb~
/usr/local/lib/ruby/gems/2.5.0/gems/hanami-1.2.0/lib/hanami/components/components.rb:474:in module_eval' /usr/local/lib/ruby/gems/2.5.0/gems/tilt-2.0.8/lib/tilt.rb:43:innew’

I found that this error is because at hanami-view-1.2.0/lib/hanami/view/rendering/templates_finder.rb templates_path globs as follows and default engines is defined as ‘*’ so that backup file *.erb~ is also selected:

  def templates_path(*parts)
    Dir.glob("#{ parts.join(separator) }.#{ format }.#{ engines }")

Could anybody let me know how to narrow engines only to ‘erb’ rather than ‘*’, or ignore tilde(~)?

Thank you!


Which editor are you using? My advice is to turn off your editor’s auto-backup feature. I’m guessing you’re using git so there’s no real need for the ~ files anymore.


I agree that turning-off of editor auto-backup is one of workaround, but it effects all of editing work other than Hanami development.

From my experience, recognizing backup-file as one of necessary file by a system is very few so that I hope Hanami ignore that.