【问题标题】:Owl carousel rails working in development mode but not on HerokuOwl carousel rails 在开发模式下工作,但在 Heroku 上不工作
【发布时间】:2016-03-31 05:49:30
【问题描述】:

我已经安装了 owl carousel rails gem,使用 spree 3.0.4,按照说明进行操作。 但我的代码在 localhost 上运行,但不在 heroku 上。我尝试使用 js 文件而不是 gem,但这也没有帮助。

这是它的模板代码_artist_show.html.erb

<div class="carousel-container">
                            <h2 class="carousel-title">Our Skilled Artists</h2>
                            <div class="row">
                                <div id="artists-brief" class="owl-carousel from-theblog-carousel from-theblog-wide" style="display:inline;">

                                    <%ArtistProfile.take(6).each do |artist|%>
                                        <article class="article">
                                            <div class="article-media-container">
                                                <a ><img src="<%=artist.a_img(:thumb)%>" class="img-responsive" alt="<%=artist.a_name%>"></a>
                                            </div><!-- End .article-media-container -->

                                            <div class="article-meta-box" style="padding-left:0;padding-right:0;">
                                                <span class="article-icon article-date-icon"></span>
                                                <span class="meta-box-text"><%=artist.a_dob%></span>
                                            </div><!-- End .article-meta-box -->

                                            <h3><a ><%=artist.a_name%></a></h3>
                                            <span class="meta-box-text"><%=truncate(artist.a_skills,length: 60)%></span>
                                            <hr/>
                                            <p><%=truncate(artist.a_brief,length: 100)%></p>
                                            <a href="/artist_profiles/<%=artist.id%>" class="readmore" role="button">Read More</a>
                                        </article><!-- End .article -->
                                    <%end%>    

                                </div><!-- End .container -->
                            </div><!-- End .container -->
                        </div><!-- End .carousel-container -->

<%=javascript_tag do%>
$(document).ready(function(){
$("#artists-brief").owlCarousel({

      autoPlay: 3000, 

      items : 2,
      itemsDesktop : [1199,3],
      itemsDesktopSmall : [979,3]

    });
     $('.owl-pagination').css({"display":"none"});

    });
<%end%>  

我也尝试将 js 代码放在主 js 文件中,但它仍然在 dev 中工作,但在 heroku 上没有。 请帮忙

【问题讨论】:

    标签: ruby-on-rails heroku spree


    【解决方案1】:

    确保您已在生产环境中启用资产预编译。

    在文件 /config/environments/production.rb 中确保这些存在。

    config.assets.compile = true

    config.assets.precompile = ['.js', '.css', '*.css.erb']

    如果您没有在 heroku 中自动预编译资产,则运行以下命令来预编译资产

    RAILS_ENV=production bundle exec rake assets:precompile

    在你推动之前。

    【讨论】:

    • 非常感谢您的调查,但我已经这样做了。但是我得到了它不工作的原因,从数据库中提取的数据有像 "(" ")" "\" '"' 这样的字符,它们会破坏代码。一旦我清理它,它就开始工作了。它在 localhost 上工作的原因是因为我只有测试数据,它只是简单的字符串
    猜你喜欢
    • 1970-01-01
    • 2012-08-23
    • 2018-01-23
    • 2011-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-27
    • 1970-01-01
    相关资源
    最近更新 更多