Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partials not found exception in Handlebars.js #35

Closed
twyfordr opened this issue Sep 28, 2012 · 18 comments
Closed

partials not found exception in Handlebars.js #35

twyfordr opened this issue Sep 28, 2012 · 18 comments

Comments

@twyfordr
Copy link

I've tried several different things, but can't get my partial to be recognized by Handlebars. I'm using handlebars_assets 0.6.6 and rails 3.2.3 (although I've also tried against 3.2.8). My templates are working, just not partials. My partial is in a subdirectory named goals and is named _steps.jst.hbs. I'm trying to access it as goal_steps.

I'm getting an exception in invokePartial() of Handlebars.js that the partial can't be found. The partials array is empty.

I am using the JST namespace. I set a breakpoint in tilt_handlebars after reading another issue, and I see the call to register_partial with the correct partial name.

What else should I try?

@leshill
Copy link
Owner

leshill commented Sep 28, 2012

Hi @twyfordr,

You should be accessing it as '_goal_steps' (see the discussion in the README https://github.com/leshill/handlebars_assets#partials).

One thing to note is that you can see the partials that have been registered with Handlebars. In the JS console, take a look at:

Handlebars.partials

That should have the partial in it.

@twyfordr
Copy link
Author

twyfordr commented Oct 1, 2012

I should have mentioned that I was using the JS console when troubleshooting - Handlebars.partials is empty. I do see my templates under the JST object. No partials.

@leshill
Copy link
Owner

leshill commented Oct 1, 2012

Hi @twyfordr,

How are you including your templates on the page? Is the template being included into application.js or another manifest file?

From the web inspector (using Chrome/Safari or Firebug in FF) you should see the template in your JS source for the page.

@pboling
Copy link

pboling commented Dec 9, 2012

My partials work in versions 0.4.4, 0.6.6, and 0.6.7, but when I upgrade to 0.7.1 I get the error Uncaught Error: The partial snapshot could not be found. Actually after git bisecting the error to that gem update, reverting back to 0.4.4, and then re-upgrading to 0.7.1, now everything works fine.

Not sure what happened to cause the error.

@leshill leshill closed this as completed Dec 9, 2012
@pboling
Copy link

pboling commented Dec 12, 2012

I spoke too soon. I now have the same problem in prod. It works fine in dev and staging now, but I get the unknown partial error Uncaught Error: The partial snapshot could not be found in production.

@leshill
Copy link
Owner

leshill commented Dec 12, 2012

Hi Peter,

Interesting, please check the results of looking at Handlebars.partials in the web inspector on both development and production.

@leshill leshill reopened this Dec 12, 2012
@pboling
Copy link

pboling commented Dec 13, 2012

I had to rollback production. Result from staging, running the same code as production was:

Handlebars.partials
ReferenceError: Handlebars is not defined

This is interesting. It means that the pages I have been so far able to access on staging hadn't been using handlebars, which is why I assumed staging was working. I think it was working in dev on new handlebars, with old partial syntax, but maybe that was an artifact of something else.

I now think the issue is that I upgraded and didn't know to upgrade how partials were referenced. I am doing that now.

@pboling
Copy link

pboling commented Dec 13, 2012

On dev, on a page where I know partials are used, after switching to the new syntax to render a partial at snapshots/_snapshot.hbs like this ``, I get this error:Uncaught Error: The partial _snapshots_snapshot could not be found

When I inspect as you suggested I get a list of partials that only has one file prefixed by _ and is missing almost all of my partials.
Handlebars partials

@leshill
Copy link
Owner

leshill commented Dec 13, 2012

Hi @pboling,

Are the rest of the files regular templates? Or just misnamed partials?

@pboling
Copy link

pboling commented Dec 13, 2012

@leshill It is very strange. I do have a partial that has the same name as a template. Here is the full list of my templates dir:

∴ find app/assets/templates
app/assets/templates
app/assets/templates/connectors
app/assets/templates/connectors/screen.hbs.erb
app/assets/templates/connectors/screen_none.hbs
app/assets/templates/invite
app/assets/templates/invite/_invite_using_email.hbs
app/assets/templates/invite/_invite_using_facebook.hbs
app/assets/templates/invite/invite_cell.hbs
app/assets/templates/invite/screen.hbs
app/assets/templates/legacy
app/assets/templates/legacy/_convo_bubble_rest.hbs.erb
app/assets/templates/legacy/acquaintances_screen.hbs.erb
app/assets/templates/legacy/conversations_screen.hbs.erb
app/assets/templates/legacy/convo_bubble_left.hbs.erb
app/assets/templates/legacy/convo_bubble_right.hbs.erb
app/assets/templates/matches
app/assets/templates/matches/conversation.hbs.erb
app/assets/templates/matches/match_box.hbs.erb
app/assets/templates/matches/nav_locked.hbs.erb
app/assets/templates/matches/nav_thread.hbs.erb
app/assets/templates/matches/pane_conversation.hbs.erb
app/assets/templates/matches/pane_locked.hbs.erb
app/assets/templates/matches/pane_maybes.hbs.erb
app/assets/templates/matches/pane_pending.hbs.erb
app/assets/templates/matches/pane_revealed.hbs.erb
app/assets/templates/matches/pending_box.hbs.erb
app/assets/templates/matches/screen.hbs.erb
app/assets/templates/nav
app/assets/templates/nav/nav.hbs.erb
app/assets/templates/settings
app/assets/templates/settings/_email.hbs.erb
app/assets/templates/settings/_photo.hbs
app/assets/templates/settings/_photos.hbs.erb
app/assets/templates/settings/screen.hbs
app/assets/templates/shared
app/assets/templates/shared/_avatar.hbs
app/assets/templates/shared/_avatar_large.hbs
app/assets/templates/shared/snapshot.hbs
app/assets/templates/snapshots
app/assets/templates/snapshots/_snapshot.hbs
app/assets/templates/snapshots/finished.hbs
app/assets/templates/snapshots/karma_10f.hbs.erb
app/assets/templates/snapshots/karma_10f_cell.hbs
app/assets/templates/snapshots/no_snapshots.hbs.erb
app/assets/templates/snapshots/screen.hbs

@pboling
Copy link

pboling commented Dec 13, 2012

@leshill Now if I grep that for just the partials, and compare it to my list, I am left scratching my head::

∴ find app/assets/templates | grep /_
app/assets/templates/invite/_invite_using_email.hbs
app/assets/templates/invite/_invite_using_facebook.hbs
app/assets/templates/legacy/_convo_bubble_rest.hbs.erb
app/assets/templates/settings/_email.hbs.erb
app/assets/templates/settings/_photo.hbs
app/assets/templates/settings/_photos.hbs.erb
app/assets/templates/shared/_avatar.hbs
app/assets/templates/shared/_avatar_large.hbs
app/assets/templates/snapshots/_snapshot.hbs

Handlebars partials

@leshill
Copy link
Owner

leshill commented Dec 13, 2012

Hi @pboling,

Have you just changed the settings/_photos.hbs file recently? It looks like only that file was actually recompiled. All the others have names from the old partial behavior.

On your dev environment, you should run rake tmp:clear to clear out any pre-compiled templates and then check.

@pboling
Copy link

pboling commented Dec 13, 2012

@leshill rake tmp:clear did not seem to have an effect. But, yes, I did change that partial in material ways recently. I am now changing them all by adding the following to each one:

<script>
  // TODO: Delete This script tag
</script>

@pboling
Copy link

pboling commented Dec 13, 2012

After changing all my partials with the tag as above, re-running rake tmp:clear and restarting my server I am still having the exact same object returned from Handlebars.partials as before, with only the one with an _.

@leshill
Copy link
Owner

leshill commented Dec 13, 2012

Hi @pboling,

Just to be clear, running rake tmp:clear in development will only affect development and only if you are not putting them back into the public folder. The exact configuration escapes me at the moment, but if you have files in public/assets you will be pulling the files from there.

@pboling
Copy link

pboling commented Dec 13, 2012

Full disclosure: I am brand new to handlebars, coming into a project that makes extensive use of it with Backbone.js for the views. It uses the asset pipeline, and is on latest rails and Ruby.

And, yes I have also recently run rake assets:precompile locally... so that is fing me up.

@pboling
Copy link

pboling commented Dec 13, 2012

WOW. You are a bad ass @leshill. Thanks for fixing me. :)

@leshill
Copy link
Owner

leshill commented Dec 13, 2012

Hi @pboling,

No worries, this has cropped up before and nailing down what is happening and what to do to get it right is useful (and going into the README.) That said, I am being kicked out of this coffee shop.

Good luck!

@leshill leshill closed this as completed Dec 16, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants