leshill / handlebars_assets

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

Views don't compile unless in application.js #56

Closed runemadsen closed 11 years ago

runemadsen commented 11 years ago

I have a separate .js file that gets compiled, called shared.js. If I add handlebars.runtime and require my views in that file, it won't work.

leshill commented 11 years ago

Hi @runemadsen,

Do you have an example of how this fails? The description sounds exactly like our setup (multiple JS assets are precompiled); each set includes whatever templates are necessary.

runemadsen commented 11 years ago

Thanks. It's hard to debug, because the views are just not there. I have 2 files:

application.js

//= require jquery
//= require jquery_ujs
//= require handlebars.runtime
//= require_directory ./some_views

shared.js

//= require handlebars.runtime
//= require_directory ./other/code
//= require_directory ./other/views

Everything in application.js works. The views get compiled, and it's all great. Everything BUT the views work in shared.js. Which means, that it's all included on the page, but my views are not in the HandlebarTemplates variable.

If I change application.js to this, all the views show up, including the ones from shared.js:

//= require jquery
//= require jquery_ujs
//= require handlebars.runtime
//= require_directory ./some_views
//= require_directory ./other/views
leshill commented 11 years ago

Hi @runemadsen,

What is config.assets.precompile set to in your environment file?

runemadsen commented 11 years ago

In production.rb:

config.assets.precompile += ['shared.js']

Maybe that should go in application.rb, so it's effective in development also?

leshill commented 11 years ago

Hi @runemadsen,

Yup :)

runemadsen commented 11 years ago

Thanks so much. Really appreciate it.

leshill commented 11 years ago

Hi @runemadsen,

No worries, good luck!