1

I have read and seen the implementations of Trigger.io + Backbone.js - my question though is regarding using the backbone-boilerplate framework specifically.

I am using Backbone-Boilerplate for my project along with the Backbone-LayoutManager by the same author. When I do a build with Trigger, my views aren't loaded in at all. After doing (a lot) of Googling, I think it has something to do with the root path of the application which is used to build the full path to the files which are fetched via AJAX. (See https://github.com/tbranyen/backbone-boilerplate/wiki/Relative-path-setup-notes)

I followed the instructions in the above link to see if I could get my app running from http://localhost/myapp/ as opposed to http://mypp.local and sure enough it worked. However I cannot set these routes manually for running on the device as I am not sure what they are going to be for each build across all devices.

Any ideas on how to get Backbone-Boilerplate template loading and Trigger.io playing nicely together?

matt_d_rat
  • 85
  • 1
  • 8

1 Answers1

1

If the path is different per device, it might make sense to explore the options of a variable app.root. This could be achieved through something like location.pathname. I'm not familiar at all with trigger.io, but would something like this work:

app.root = location.pathname;

This would set the root to something like: /e034fde/random/path/ dynamically.

tbranyen
  • 8,507
  • 1
  • 21
  • 18
  • Ooh, that gets me half way there. My app now works when I go to both `http://myapp.local` and `http://localhost/myapp/` but still no luck with the Trigger build. Do you think it could be to do with same-origin-policy possibly? or something strange like that? By the way Trigger.io is free to download and try. Really appreciate the help. – matt_d_rat Sep 26 '12 at 23:02
  • I tried getting trigger.io to work as a chrome extension, but its incredibly frustrating that its not painfully obvious how to get a button to display (still don't have it working to test)... Give something like this a shot: `app.root = location.pathname.split("/").slice(0, -1).join("/") + "/";` Edit: Lord I hate this comment interface, key saves instead of newlines... – tbranyen Sep 26 '12 at 23:29
  • Still the same result, works for `http://myapp.local` and `http://localhost/myapp/` but not for Trigger.io build. FYI, I'm testing in the iOS simulator, latest build (iOS6 10A403). Normally I just symblink the src folder for the build, make sure you have the config.json and identity.json in the folder. – matt_d_rat Sep 26 '12 at 23:44
  • I managed to get Trigger to logout the path of app.root, it came out with something along the lines of: `/Users/Matt/Library/Application%20Support/iPhone%20Simulator/6.0/Applications/blah-blah/Library/Application%20Support/Forge/assets/src/` So perhaps its not liking loading via that path without `file://` ? – matt_d_rat Sep 26 '12 at 23:51
  • Concat location.protocol + '//' + app.root to see if generating a path with file:///Users/Matt/ etc.. would work. No such luck. ;-( – matt_d_rat Sep 27 '12 at 00:01
  • Come to think of it, if you disable `pushState` you should be able to set the root to relative like, `app.root = ""`. Ensure you remove the `` inside `index.html` as well. This should load the assets local to the folder. – tbranyen Sep 27 '12 at 02:36
  • Ok my problem is not yet solved, but I managed to get it (sort of) working, the only problem it works in the strangest of ways, which is wrong... I set `pushState` to false and set the root relative like `app.root = ''`. Ensured there was no `` inside `index.html` This on its own did not work. I was curious though to find out what error was thrown by the ajax request so I logged out the error received by adding a .fail() call. I was surprised to see returned in the responseText the html for my template. I obviously don't want to render the template in an error method. – matt_d_rat Sep 27 '12 at 07:13
  • Ok, did some more digging and I found if I set the settings as cited above and enable `isLocal: true` on the ajax request, the templates load correctly. Although, I'm not sure really why. But this is only the case if `pushState` is set to false. What is the purpose of setting this to `false`? Do I lose any functionality by doing so? And if yes, is there a way to solve my problem without compromising of functionality? – matt_d_rat Sep 27 '12 at 07:17
  • On iOS our pages are served from file-scheme URIs (after switching to http for a while), so not sure why isLocal is making a difference - assuming you're using the latest v1.4 platform version? I wouldn't recommend using pushState in general as it's not supported on Android... again not sure why it's affecting template loading semantics here though! – James Brady Oct 03 '12 at 10:14