Jump to content

The ultimate community for Ruby on Rails developers.


Fingerprint asset problems.

angular depend_on_asset asset_path precompiler

  • Please log in to reply
3 replies to this topic

#1 doodloo



  • Members
  • 4 posts

Posted 19 April 2014 - 03:56 PM



i'm trying to work with Rails 4 and Angular, and something is really bothering me.

As some of you might know, AngularJS is based on dynamically loading HTML templates (i cannot use a templateCache).

So here is a snippet of my app.js.coffee.erb (i renamed it to this, so i can use asset_path which is supposed to append the fingerprint hash of any compiled asset once it's pushed in production, right?):

# At the beginning of the file, i have put this (i have tried any combination with //=, #=, #//= or //#=... they all work. Which one am i supposed to use within a .js.coffee.erb file?):
//= depend_on_asset "users/users.html"
//#= depend_on_asset "users/users.html"
#= depend_on_asset "users/users.html"
Then, the angular router is configured with something like:
# This is supposed to generate the right fingerprint for an asset, right?
templateUrl:  '<%= asset_path '/assets/users/users.html' %>'
My assets are in HAML format (E.g. Users.html.haml), and are located in "Rails.root / app / assets / templates".
i ended up trying pretty much everything i could find on the subject, including having an initializer doing something like this:
Rails.application.assets.register_mime_type 'text/html', '.html'

Rails.application.assets.register_engine '.haml', Tilt::HamlTemplate
Rails.application.assets.register_engine '.slim', Slim::Template
Rails.application.config.assets.precompile  += [
                                              # Templates.

Locally, this perfectly works. Angular is able to do it's $http request to the server, and retrieve the template when needed. However in production, it fails with 404, as it says that '/assets/users/users.html' doesn't exist on the server... Which means that asset_path doesn't produce the right output.
Is there anything i can do to solve this issue please?
Thanks a lot,

#2 doodloo



  • Members
  • 4 posts

Posted 19 April 2014 - 04:51 PM

Hello again,


i just have checked my server logs, and it appears that the templates are correctly precompiled:

 ** [out :: XXXXXXXX] I, [2014-04-19T18:33:14.763460 #2967]  INFO -- : Writing /XXXXXX/releases/20140419163132/public/assets/users/users-c7f822f89a4da1690743179764c0b689.html

Then, if i point a web browser to the website URL/assets/users/users-c7f822f89a4da1690743179764c0b689.html, the asset is here.

However, the application.js that get compiled (And which should contain the output from asset_path('/assets/users/users-HASH.html')) instead contains plain '/assets/users/users.html'


Why? How, from an app.js.coffee.erb, can i point to the filename that will be outputted by the assets compilation process instead of the vanilla one?




#3 doodloo



  • Members
  • 4 posts

Posted 19 April 2014 - 05:01 PM

Ah! i finally found the solution to this problem. i will post it as soon as i will get back home.


Thanks anyway!


#4 doodloo



  • Members
  • 4 posts

Posted 26 May 2014 - 04:44 PM   Best Answer

What was very important was to use the correct path for the asset_path helper method. You have to use the path without assets/folder.

For instance, if you have an file named:


Then you'll have to use:

<%= asset_path 'users/users.html' %>

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users