【问题标题】:Not displaying star rating on production (heroku)不显示生产星级(heroku)
【发布时间】:2018-02-10 17:58:16
【问题描述】:

我正在使用 gem ratyrate,在本地它工作正常,但在生产中它会生成图像的 404 错误。

我找到了一些解决方案,但它们不起作用

/initializer/raty_helper.rb https://github.com/wazery/ratyrate/blob/master/lib/ratyrate/helpers.rb

raty.js.rb

$.fn.raty.defaults.half = false;
$.fn.raty.defaults.halfShow = true;
$.fn.raty.defaults.path = '<%= asset_path('images') %>';
$.fn.raty.defaults.cancel = false;

$(function(){
  $(".star").each(function() {
    var $readonly = ($(this).attr('data-readonly') == 'true');
    var $half     = ($(this).attr('data-enable-half') == 'true');
    var $halfShow = ($(this).attr('data-half-show') == 'true');
    var $single   = ($(this).attr('data-single') == 'true');
    $(this).raty({
      score: function() {
        return $(this).attr('data-rating')
      },
      number: function() {
        return $(this).attr('data-star-count')
      },
      half:        $half,
      halfShow:    $halfShow,
      single:      $single,
      path:        $(this).attr('data-star-path'),
      starOn:      '/star-on.png',
      starOff:     '/star-off.png',
      starHalf:    '/star-half.png',
      cancel:      $(this).attr('data-cancel'),
      cancelPlace: $(this).attr('data-cancel-place'),
      cancelHint:  $(this).attr('data-cancel-hint'),
      cancelOn:    '/cancel-on.png',
      cancelOff:   '/cancel-off',
      noRatedMsg:  $(this).attr('data-no-rated-message'),
      round:       $(this).attr('data-round'),
      space:       $(this).attr('data-space'),
      target:      $(this).attr('data-target'),
      targetText:  $(this).attr('data-target-text'),
      targetType:  $(this).attr('data-target-type'),
      targetFormat: $(this).attr('data-target-format'),
      targetScoret: $(this).attr('data-target-score'),
      readOnly: $readonly,
      click: function(score, evt) {
        var _this = this;
        if (score == null) { score = 0; }
        $.post('<%= Rails.application.class.routes.url_helpers.rate_path %>',
        {
          score: score,
          dimension: $(this).attr('data-dimension'),
          id: $(this).attr('data-id'),
          klass: $(this).attr('data-classname')
        },
        function(data) {
          if(data) {
            // success code goes here ...

            if ($(_this).attr('data-disable-after-rate') == 'true') {
              $(_this).raty('set', { readOnly: true, score: score });
            }
          }
        });
      }
    });
  });
});

【问题讨论】:

  • 你能发一些日志吗?
  • @bangbang GET domain.com/assets/star-off.png 404(未找到)star-off.png

标签: ruby-on-rails heroku raty


【解决方案1】:

添加到您的config/environments/production.rb

config.serve_static_assets = true

【讨论】:

  • 您可以尝试在生产模式下启动您的开发服务器吗?
  • 我通过做这个 rails assets: precompile 解决了这个问题
【解决方案2】:

解决办法是执行这个命令:

rails assets:precompile 

【讨论】:

  • 与此相关意味着您每次资产更改时都必须运行此程序,否则您将得到一个陈旧的版本。这似乎是暂时的
猜你喜欢
  • 1970-01-01
  • 2015-07-29
  • 1970-01-01
  • 1970-01-01
  • 2021-05-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多