Rails 4 - 如何访问 gem 预编译资源



我有一个应用程序,我正在预编译要部署到 Heroku 的资产。我正在使用使用一些内部图像的宝石。我跑。

RAILS_ENV=production bundle exec rake assets:precompile

并且图像已编译,实际上我可以在public/assets/jquery.raty/目录中(它们应该在的位置)中看到它们。 例如

myapp/public/assets/jquery.raty/star-on-4db6f75f3608bbd77fa4bc3959097c33.png

问题是 gem 的 javascript 找不到图像,因为它在内部引用了它们()。因此,我更改了配置以使用 <%= asset_path"文件名"%> 添加图像(我将文件更改为 .js.erb )。本地工作正常(因为我没有在开发中预编译),但是部署到 heroku 后,图像被引用为类似

/assets/jquery.raty/star-on.png

没有 md5 指纹。

有人知道我做错了什么?还是在预编译宝石资产时缺少一些东西?

谢谢。

对于信息,我必须执行以下操作才能使其正常工作:

$('#star').raty({
  starOn: '<%= image_path('star-on.png') %>',
  starOff: '<%= image_path('star-off.png') %>',
  path: '',
  scoreName: 'star',
  space: true 
});

好的,似乎asset_path没有使用图像的指纹。我不得不使用image_path并稍微调整一下以使其与库一起使用。

这种方式对我有用

  $(this).raty({
    scoreName: "seller_rating",
    starOn: '<%= asset_url 'star-repassa-on.png' %>',
    starOff: '<%= asset_path 'star-repassa-off.png' %>',
    path: '',
    readOnly: true,
    score: function () {
      return $(this).attr('data-score');
    }
  })

最新更新