ไอคอนบูต Rails 5.1.2 ไม่ได้ให้บริการในการผลิต

นี่คือสถานที่ที่ยอดเยี่ยม ฉันหวังว่าจะมีความสามารถเพียงพอที่จะช่วยแก้ไขปัญหาได้ในเร็วๆ นี้

ได้โปรดมีคนช่วยด้วย!!!

ฉันได้ดู YouTube หลายชั่วโมงและอ่านทุกโพสต์เกี่ยวกับการรวบรวมไปป์ไลน์สินทรัพย์ล่วงหน้าบนเว็บ

ไม่ว่าด้วยเหตุผลใดก็ตามฉันจึงตัดสินใจใช้ Rails 5.1.2 และไม่รู้ว่านั่นเป็นปัญหาหรือไม่

glyphicons ไม่แสดงผลบน Heroku หรือใช้งาน

rails s -e production 

บน Ubuntu ท้องถิ่นของฉัน

ฉันพิมพ์

rake assets:precompile RAILS_ENV=production

และได้รับ

I, [2018-01-01T16:05:07.261287 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf
I, [2018-01-01T16:05:07.261968 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-e395044093757d82afcb138957d06a1ea9361bdcf0b442d06a18a8051af57456.ttf.gz
I, [2018-01-01T16:05:07.263049 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff
I, [2018-01-01T16:05:07.264510 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/glyphicons-halflings-regular-fe185d11a49676890d47bb783312a0cda5a44c4039214094e7957b4c040ef11c.woff2
I, [2018-01-01T16:05:07.289833 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-c29c47294834d3d47956f910a3182df4a7db7d5864e82c6f758027f30669bafb.js
I, [2018-01-01T16:05:07.290028 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-c29c47294834d3d47956f910a3182df4a7db7d5864e82c6f758027f30669bafb.js.gz
I, [2018-01-01T16:05:14.175848 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-b896db4d9b9e69049347e71a1825dcdc1a4eed9147196fdd761afe6f12b556d4.css
I, [2018-01-01T16:05:14.176068 #4745]  INFO -- : Writing /home/dracos/rails/video-store/public/assets/application-b896db4d9b9e69049347e71a1825dcdc1a4eed9147196fdd761afe6f12b556d4.css.gz

แต่ใน log/production.log ฉันได้รับ

FATAL -- : [849248f2-cd3c-4912-a10d-4f63bd5857ae] ActionController::RoutingError (ไม่มีเส้นทางที่ตรงกับ [GET] /assets/glyphicons-halflings-regular.ttf):

FATAL -- : [dfae9054-ad8a-4553-85a3-c55d55b1946c] ActionController::RoutingError (ไม่มีเส้นทางที่ตรงกับ [GET] /assets/glyphicons-halflings-regular.woff):

ฯลฯ...

ฉันไม่เข้าใจ?!? ฉันจะไม่แสร้งทำเป็นเข้าใจสิ่งที่เกิดขึ้นทั้งหมดภายใต้ฝากระโปรงของท่อส่งสินทรัพย์และต้องการตอนนี้ที่จะไม่ใช่มือใหม่ แต่นี่!?!? ทำไม ใครสามารถแจ้งให้เราทราบ?

/app/assets/stylesheets/bootstrap.css ของฉันได้รับการแก้ไขเพื่อแสดง

@font-face {
    font-family: 'Glyphicons Halflings';

    src: url('../assets/glyphicons-halflings-regular.eot');
    src: url('../assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), 
    url('../assets/glyphicons-halflings-regular.woff2') format('woff2'),   
    url('../assets/glyphicons-halflings-regular.woff') format('woff'), 
    url('../assets/glyphicons-halflings-regular.ttf') format('truetype'), 
    url('../assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

และที่น่าสนใจก็คือส่วน /assets/ จะถูกเพิ่มเข้าไป แม้ว่าฉันจะปล่อยส่วนนั้นไว้นอกเส้นทาง URL ในไฟล์ด้านบนทั้งหมดก็ตาม ฉันได้ลองทุกอย่างแล้ว ใครสามารถช่วยได้บ้าง? ความช่วยเหลือใด ๆ ที่จะได้รับการชื่นชมมาก

ไชโย


person Just Matt for now    schedule 01.01.2018    source แหล่งที่มา


คำตอบ (4)


หากคุณต้องการเก็บทรัพย์สินของคุณไว้ในโฟลเดอร์ /assets เท่านั้น และไม่อยู่ในโฟลเดอร์ /public

ขั้นแรก คุณสามารถวางไฟล์ฟอนต์ของ glyohicons ทั้งหมดไว้ในโฟลเดอร์ /assets/fonts (หากไม่ได้สร้าง /fonts ให้สร้างขึ้นใหม่)

ประการที่สอง แปลงไฟล์ .css ของคุณเป็นไฟล์ .scss โดยเปลี่ยนชื่อไฟล์ เพื่อให้คุณสามารถใช้เมธอด Assets_path ในสไตล์ชีตได้

จากนั้น แจ้งให้แอปพลิเคชันของคุณทราบว่าคุณมีแบบอักษรเป็นเนื้อหาด้วยโดยเพิ่มบรรทัดต่อไปนี้ในไฟล์ application.rb ของคุณ

config.assets.paths << "#{Rails.root.to_s}/app/assets/fonts"

จากนั้นเปลี่ยน URL ของคุณในไฟล์ bootstrap.scss ด้วยวิธีต่อไปนี้

src: url(asset_path('glyphicons-halflings-regular.eot'));

รีสตาร์ทเซิร์ฟเวอร์และตรวจสอบ แบบอักษรควรได้รับการโหลดเป็นสินทรัพย์

ขอบคุณ.

person Arth Thakkar    schedule 01.01.2018
comment
ใช่! ได้ผล แต่ไม่จำเป็นต้องทำส่วน config.assets.paths ‹‹ #{Rails.root.to_s}/app/assets/fonts ฉันยังใช้ font-url(asset-path('glypgicons-halflings-etc, ฯลฯ.... - person Just Matt for now; 01.01.2018

คุณสามารถเขียนไปป์ไลน์สินทรัพย์ คุณสามารถย้ายไฟล์ฟอนต์ของคุณไปยังโฟลเดอร์สาธารณะ เช่น สร้างโฟลเดอร์ภายใน public/assets ชื่อ fonts ซึ่งกำลังมองหา public/assets/fonts/ จากนั้นอัปโหลดไฟล์ฟอนต์ของคุณที่นี่ ซึ่งมีลักษณะเหมือน public/assets/fonts/glyphicons-halflings-regular.woff และเปลี่ยนพาธ เช่น /assets/fonts/glyphicons-halflings-regular.woff หรือ /assets/glyphicons-halflings-regular.wof

หวังว่าจะช่วยเหลือ

person fool-dev    schedule 01.01.2018

คุณสามารถแก้ไขปัญหานี้ได้ด้วยวิธีนี้ -

  1. สร้างชื่อโฟลเดอร์ "fonts" ภายในไดเรกทอรี app/assets และวางแบบอักษร bootstrap (glyphicons-halflings-regular.eot, glyphicons-halflings-regular.ttf, glyphicons-halflings-regular.woff ฯลฯ) แบบอักษรภายในไดเรกทอรีแบบอักษร
  2. ตอนนี้เพิ่มบรรทัดนี้ใน config/application.rb

    config.assets.paths << Rails.root.join("app", "assets", "fonts")
    
  3. ตอนนี้คุณต้องเปลี่ยนชื่อ app/assets/stylesheets/application.css เป็น app/assets/stylesheets/application.css.scss และวางโค้ดร้อง -

    @font-face {
     font-family: 'Glyphicons Halflings';
     src: url(asset-path("glyphicons-halflings-regular.eot"));
     src: url(asset-path("glyphicons-halflings-regular.eot?#iefix")) format("embedded-opentype"),
         url(asset-path("glyphicons-halflings-regular.woff2")) format("woff2"),
         url(asset-path("glyphicons-halflings-regular.woff")) format("woff"),
         url(asset-path("glyphicons-halflings-regular.ttf")) format("truetype"),      
        url(asset-path("glyphicons-halflings-regular.svg#glyphicons_halflingsregular")) format("svg");
    }
    
  4. ตอนนี้เพิ่มแบบอักษรเพื่อ config/initializers/assets.rb สำหรับเนื้อหาเพิ่มเติมที่คอมไพล์ล่วงหน้า

    Dir.glob("#{Rails.root}/app/assets/fonts/**/").each do |path|
      Rails.application.config.assets.paths << path
    end
    
  5. รีสตาร์ทเว็บเซิร์ฟเวอร์

ฉันหวังว่าตอนนี้มันควรจะทำงาน

person Sahidur Rahman Suman    schedule 01.01.2018

สร้างจากคำตอบของ fool-dev... การใช้ Rails 5.1.4, yarn และ webpacker... สิ่งที่ต้องทำก็แค่คัดลอกไฟล์ฟอนต์ bootstrap จาก bootstrap/dist/fonts/ ถึง public/fonts และ ปรับใช้อีกครั้ง

ไม่ต้องยุ่งกับไฟล์ bootstrap/dist/css/bootstrap.* ที่ให้มาเลย

person Dave Collins    schedule 18.03.2018
comment
ขอบคุณ @DaveCollins ตั้งแต่นั้นมา ฉันพบว่าสถานการณ์ของฉันดีพอที่จะเข้าถึง CDN ได้โดยตรงแล้ว เดิมทีฉันรู้สึกไม่สบายใจที่จะใช้ CDN เนื่องจากกลไกถูกซ่อนไว้เกินกว่าจะเข้าใจได้ว่าเกิดอะไรขึ้น - person Just Matt for now; 20.03.2018