CSS和图像文件在Heroku不起作用



我正在使用一个小型Web应用程序,并且在我的笔记本电脑上工作正常。但是,当部署在Heroku上时,缺少样式和图像。

Web应用链接:https://vast-crag-53030.herokuapp.com/

代码存储库:https://github.com/alokshrotri/commutestats

我正在使用Rails 5,AM在Windows 7

我能够运行以下命令,致力于Github并在Heroku上重新部署,但无济于事。

捆绑电报资产:预编译

如果我使用rails_env =生产运行,则会出现一个错误,如下所示。这里(= require_tree。(未注销。

C:Usersu0126252DocumentsGitHubcommuteStatsbin [master ≡ +0 ~3 -0 !]> bundle exec rake assets:precompile RAILS_ENV=production
(in C:/Users/u0126252/Documents/GitHub/commuteStats)
rake aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: eof (undefined)
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

如果我注释(//= require_tree。(,则输出不同。

C:Usersu0126252DocumentsGitHubcommuteStatsbin [master ≡ +0 ~1 -0 !]> bundl
e exec rake assets:precompile RAILS_ENV=production
(in C:/Users/u0126252/Documents/GitHub/commuteStats)
rake aborted!
ExecJS::ProgramError: TypeError: Object doesn't support this property or method
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
C:Usersu0126252DocumentsGitHubcommuteStatsbin [master ≡ +0 ~1 -0 !]>

尝试阅读围绕此帖子的几篇文章,但没有帮助。我当然不想添加config.assets.compile = tue代码。

周围的任何帮助都会很棒。下面的环境详细信息。很高兴提供所需的任何其他信息。

C:Usersu0126252DocumentsGitHubcommuteStatsbin [master ≡ +0 ~1 -0 !]> rails
 -v
Rails 5.0.2
C:Usersu0126252DocumentsGitHubcommuteStatsbin [master ≡ +0 ~1 -0 !]> ruby
--version
ruby 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32]
C:Usersu0126252DocumentsGitHubcommuteStatsbin [master ≡ +0 ~1 -0 !]> syste
minfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name:                   Microsoft Windows 7 Enterprise
OS Version:                6.1.7601 Service Pack 1 Build 7601
C:Usersu0126252DocumentsGitHubcommuteStatsbin [master ≡ +0 ~1 -0 !]>

所以,我首先要从"简单"开始,图像没有显示,因为您告诉它在错误的地方看。更改为:

<%= image_tag "button.png" %>

第二,您可以通过两种方式之一获得样式表:

config.assets.compile = false更改为true(不推荐(

或添加

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>

正如双思想在评论中写的,并将标志设置为false。

这是一个有效的直播版本:https://polar-refuge-16359.herokuapp.com/

我将在您的github存储库上制作PR,您可以看到我对Heroku上的版本所做的。

最新更新