leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
649 stars 159 forks source link

HandlebarsTemplates object not defined without backing model #164

Closed jwlms closed 1 year ago

jwlms commented 6 years ago

I've been trying (and failing) to integrate this gem into non-standard Rails 3 application (which is mostly JavaScript and lacks a typical backing model).

The example provided in the README is a Contact model:

templates/
  contacts/
    new.hbs
    edit.hbs
    show.hbs

My primary question is:

Does this gem work without a backing model? As following the steps in the README for my use case, provides me with a consistent error message of HandlebarsTemplates is not defined. I have templates in the templates directory and am able to manually precompile the templates and include them into the application with the runtime and access them under Handlebars.templates.generic_handlebars_template.

Is there a step I'm missing for this use case:

templates/
  generic_handlebars_template

Any help here would be greatly appreciated!

AlexRiedler commented 6 years ago

@jwlms what do you mean by a backing model? (unfamiliar with the use of that term)

AlexRiedler commented 6 years ago

Have you potentially set the template_namespace to something different then HandlebarsTemplates ?

jwlms commented 6 years ago

@jwlms what do you mean by a backing model? (unfamiliar with the use of that term)

I just mean a model in general. A Contact model, would generally have a view /contacts/new.html etc. I think you would say the contact pages have a backing Contact model. Maybe it's not that important in my case.

Have you potentially set the template_namespace to something different then HandlebarsTemplates ?

I did attempt this at an earlier point just to see if I could get this gem working, but was unsuccessful. Currently I don't have template_namespace set. It's possible it's something with my applications config though.. I will give this a try on a new Rails app.

jwlms commented 6 years ago

I'm seeing the same behavior with a new rails app. There doesn't seem to be anything created in the HandlebarsTemplates namespace. Is there possibly a step that I'm missing? (fwiw I'm using Rails 3).

jwlms commented 6 years ago

@AlexRiedler - I put up a PR to fix the issue I've run into. This seems like it should have limited side effects, but I don't know the project well.

Alternatively, to get this to work on Rails 3 I was able to add this to my application.rb file:

    config.before_initialize do
      Sprockets.register_engine '.hbs', HandlebarsAssets::HandlebarsTemplate
    end

Which could be used as an alternative to the PR if it's not up to spec.

AlexRiedler commented 1 year ago

cleaning up, going to close cause referenced PR was merged, and making sure this all works with Rails 7