Question

I have .swf files under vendor/assets/images/swf/. I need the asset path of that folder.

But this (.js.coffee.erb)

#= soundmanager2

$ ->
  soundManager.setup
    url: '<%= asset_path "swf/" %>'

is rendering this (.js):

(function() {
  var $ = jQuery;
  $(function() {
    return soundManager.setup({
      url: '/swf/'
    });
  });
}).call(this);

I am using rails 4.0.0.rc1. I am on development mode. The path /assets/swf/soundmanager2.swf returns 200, while /swf/soundmanager2.swf returns 404. The helper image_path returns /images/swf/, but /images/swf/soundmanager2.swf also returns 404.

Was it helpful?

Solution

It is not worth the trouble, because you would have to disable digest to get the name of the files right. So the solution is to fix the library. In the case of Sound Manager 2, I did this:

Some CoffeeScript that I require:

#= require soundmanager2

jQuery ->
  soundManager.swfNames =
    "/soundmanager2.swf":              "<%= asset_path('swf/soundmanager2.swf') %>"
    "/soundmanager2_debug.swf":        "<%= asset_path('swf/soundmanager2_debug.swf') %>"
    "/soundmanager2_flash9.swf":       "<%= asset_path('swf/soundmanager2_flash9.swf') %>"
    "/soundmanager2_flash9_debug.swf": "<%= asset_path('swf/soundmanager2_flash9_debug.swf') %>"

  soundManager.setup
    debugMode: <% if Rails.env.development? %>true<% else %>false<% end %>
    url: '/'

In my copy of soundmanager2.js (V2.97a.20130512), inside the definition of normalizeMovieURL:

url = ...                // After url is set

url = sm2.swfNames[url]; // Workaround

OTHER TIPS

on rails 4 all the asset helpers (image_path, asset_path and the likes) appear to only return a config.assets.prefix-prefixed path if the asset you're accessing is actually resolvable by sprockets.
put simply: it must exist in you asset path on the disk after precompilation.

therefore, asset_path('swf/') will not work since it is a directory and not a file.

also, i experienced the following: rails < 4 (sprockets, rather) copied original images (and thus swf files) and created a digested version of that same file. because of this soundmanager was still able to find the non-digested swf files even though i have config.assets.digest = true.
with rails 4, these original images are not copied anymore because they changed some precompile internals which leads soundmanager to throw up if it wants to fallback to flash.

to properly fix this soundmanager needs to be patched, like michelpm proposes.
for soundmanager-rails i started working on a fix including a proper patch for soundmanager which you can find over on github.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top