railsware / sht_rails

Shared handlebars templates for Rails 3
http://blog.railsware.com/2012/05/21/shared-handlebars-templates-for-rails-3/
MIT License
76 stars 21 forks source link

Rails 4, have to re-register handler after changing default extension name. #29

Open UnquietCode opened 8 years ago

UnquietCode commented 8 years ago

I have in my application.rb configuration changes to use an alternative file extension like hbs. However it seems like the renderer is registered before this change is made. Maybe I am doing things in the wrong order, however my workaround is to re-register the handlebars renderer after I've updated the extension.

ShtRails.template_extension = 'hbs'
ShtRails.action_view_key = 'hbs'
ShtRails.template_namespace = 'HighlyHBS'
ShtRails.template_base_path = Rails.root.join("app", "views")

# need to re-register the handler
ActiveSupport.on_load(:action_view) do
  ActionView::Template.register_template_handler(::ShtRails.template_extension.to_sym, ::ShtRails::Handlebars)
end

That last bit is just copied from the sht source: https://github.com/railsware/sht_rails/blob/e52ab72b3e5eef0794787485edcac188a4812a49/lib/sht_rails/handlebars.rb#L39

le0pard commented 8 years ago

Hello. Try to set this settings after Bundler.require(:default, Rails.env) in config/application.rb