我正在使用rails 4.2并使用Windows 7 64位开发我的rails应用程序, 一切都在开发模式下工作正常,但一旦我试图在生产模式下运行我的应用程序,我的应用程序布局,CSS和JavaScript都破了, 我相信它与资产管道有关,但我不太明白,请给我一些帮助。
这是
下的资产结构vendor/assets
- public_assets
- font
- img
- bg
- favicon
- images
- proteam
- png
- ualanding
- portofolio
- thumbnail
- fullsize
- css
- js
- sass
- vendor
- bootstrap
- css
- fonts
- js
- font-awesome
- css
- fonts
- less
- scss
- jquery
- magnific-popup
- ninja-slider
- scroolreveal
- vid
- Static_Dev
- assets
- img
- flags
- avatars
- css
- js
- libs
- views
- fonts
我在这些文件中调用了我的资产:
admin.css
admin.js
public.css
public.js
我还将此添加到我的assets.rb:
Rails.application.config.assets.precompile += %w( public.css )
Rails.application.config.assets.precompile += %w( admin.css )
Rails.application.config.assets.precompile += %w( admin.js )
Rails.application.config.assets.precompile += %w( public.js )
,这是application.rb
config.assets.paths += Dir["#{Rails.root}/vendor/public-assets/*"].sort_by { |dir| -dir.size }
config.assets.paths += Dir["#{Rails.root}/vendor/Static_Dev/*"].sort_by { |dir| -dir.size }
这是我的浏览器错误日志:
http://localhost:3000/stylesheets/public.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/javascripts/public.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/assets/img/logo.png Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/assets/img/png/UA-Landing/Img-UALanding1.png Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/assets/img/png/UA-Landing/Img-UALanding2.png Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/assets/img/png/UA-Landing/Img-UALanding3.png Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:3000/assets/vid/URBAN%20video.mp4 Failed to load resource: the server responded with a status of 404 (Not Found)
(index):372 Uncaught ReferenceError: $ is not defined(anonymous function) @ (index):372
base.js:6943 GET http://localhost:3000/uploads/house/thumbnail/8/Pensive_Parakeet.jpg 404 (Not Found)h.Ja @ base.js:6943g5 @ base.js:4017mma @ base.js:4007b9 @ base.js:4335psa @ base.js:4349W8 @ base.js:4330W8.create @ base.js:7301(anonymous function) @ www-embed-player.js:507g.De @ www-embed-player.js:507oi @ www-embed-player.js:505g.Zb @ www-embed-player.js:498(anonymous function) @ www-embed-player.js:540
base.js:6943 GET http://localhost:3000/uploads/house/thumbnail/1/Penguins.jpg 404 (Not Found)h.Ja @ base.js:6943g5 @ base.js:4017mma @ base.js:4007b9 @ base.js:4335psa @ base.js:4349W8 @ base.js:4330W8.create @ base.js:7301(anonymous function) @ www-embed-player.js:507g.De @ www-embed-player.js:507oi @ www-embed-player.js:505g.Zb @ www-embed-player.js:498(anonymous function) @ www-embed-player.js:540
base.js:6943 GET http://localhost:3000/uploads/apt/thumbnail/144/Pensive_Parakeet.jpg 404 (Not Found)h.Ja @ base.js:6943g5 @ base.js:4017mma @ base.js:4007b9 @ base.js:4335psa @ base.js:4349W8 @ base.js:4330W8.create @ base.js:7301(anonymous function) @ www-embed-player.js:507g.De @ www-embed-player.js:507oi @ www-embed-player.js:505g.Zb @ www-embed-player.js:498(anonymous function) @ www-embed-player.js:540
我运行此命令:
rake assets:预编译RAILS_ENV =生产
和结果错误如下:
C:\Users\lenovo\Documents\urbanace\urbanacecode>rake assets:precompile RAILS_ENV
=production
I, [2016-09-19T16:18:29.470690 #13608] INFO -- : Writing C:/Users/lenovo/Docume
nts/urbanace/urbanacecode/public/assets/public-78c00ecc416b598bae03765242c333f88
e2db37a2d83217a99d53e02d1e5d9de.css
I, [2016-09-19T16:18:29.525693 #13608] INFO -- : Writing C:/Users/lenovo/Docume
nts/urbanace/urbanacecode/public/assets/public-78c00ecc416b598bae03765242c333f88
e2db37a2d83217a99d53e02d1e5d9de.css.gz
I, [2016-09-19T16:18:38.402201 #13608] INFO -- : Writing C:/Users/lenovo/Docume
nts/urbanace/urbanacecode/public/assets/admin-529cbf47908b1b0636fcd9023a0f6acf3c
1bd78078f3feca7863f077f17ddf2b.css
I, [2016-09-19T16:18:38.402201 #13608] INFO -- : Writing C:/Users/lenovo/Docume
nts/urbanace/urbanacecode/public/assets/admin-529cbf47908b1b0636fcd9023a0f6acf3c
1bd78078f3feca7863f077f17ddf2b.css.gz
rake aborted!
ExecJS::RuntimeError: undefined: SyntaxError: Unexpected token: eof (undefined)
请告诉我错过了什么?
答案 0 :(得分:0)
打开config / environments / production.rb并确保将以下选项设置为true:
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
然后运行:
rake assets:precompile --trace RAILS_ENV=production
希望这有帮助!