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

时间:2022-11-10 20:37:10

I have an application an I'm precompiling the assets to deploy to Heroku. I'm using a gem which uses some internal images. I run.

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

RAILS_ENV=production bundle exec rake assets:precompile

And the images are compiled, in fact i can see them in the public/assets/jquery.raty/ directory (where they should be). E.g.

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

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

The problem is the gem's javascript cannot find the images because it's referencing to them internally (). So, I've changed the configuration to add the images using <%= asset_path "filename" %> (I changed the file to .js.erb). Locally works ok (because I'm not precompiling in development), but after deploying to heroku, the images are referenced like

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

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

Without the md5 fingerprint.

没有md5指纹。

Somebody knows what am I doing wrong? Or there's something I'm missing when precompilng gem assets?

有人知道我做错了什么?或者在预编制宝石资产时我会遗漏一些东西?

Thanks.

谢谢。

3 个解决方案

#1


3  

For info, I had to do the following to get it to work properly for me:

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

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

#2


0  

Ok, it seems that asset_path doesn't use the fingerprints for the images. I had to use image_path and tweak a little bit to make it work with the library.

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

#3


0  

this way worked for me

这种方式对我有用

  $(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');
    }
  })

#1


3  

For info, I had to do the following to get it to work properly for me:

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

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

#2


0  

Ok, it seems that asset_path doesn't use the fingerprints for the images. I had to use image_path and tweak a little bit to make it work with the library.

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

#3


0  

this way worked for me

这种方式对我有用

  $(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');
    }
  })