7

पर रेल 3.1 में खाली के रूप में दिखाया गया चित्र मैंने हाल ही में अपने रेल को 3.1 में अपडेट किया है।प्रोडक्शन (हेरोकू)

<%= asset_path('logo_symbol.png') %> 

यह renders /assets/logo_symbol.png जो विकास के वातावरण में पूरी तरह से ठीक काम करता है:

यहाँ एक हिस्सा मैं कहाँ जोड़ा है। हालांकि, जब मैं कोड को उसकेोकू पर उत्पादन में धक्का देता हूं, तो यह यूआरएल के साथ एक टूटी हुई छवि दिखाता है: assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png। मुझे लगता है कि नया नाम कुछ अनुकूलन के कारण है।

यह ध्यान रखना दिलचस्प है कि जब मैं उत्पादन पर assets/logo_symbol-135ddc8db2c9b59f032bed7db520137a.png यूआरएल पर जाता हूं, तो मुझे एक खाली पृष्ठ दिखाई देता है, लेकिन जब मैं उस यूआरएल को यादृच्छिक रूप से बदलता हूं, तो इसमें संख्या जोड़ने की तरह, यह एक पृष्ठ नहीं मिलता है। तो स्पष्ट रूप से यह उस यूआरएल पर कुछ ढूंढ रहा है। जब मैं /assets/logo_symbol.png पर सीधे उत्पादन/हेरोकू पर जाता हूं तो यह एक खाली पृष्ठ भी दिखाता है।

यदि यह कोई मदद है, तो कोड को दबाए जाने पर उसकेोकू सफलतापूर्वक प्रीकंपाइल नहीं करता है और उसके अनुयायी के दस्तावेज़ में कहा गया है कि वर्तमान में उस समस्या के लिए कोई काम नहीं है।

इसमें कोई भी सहायता की सराहना की जाएगी।

मेरा अनुमान है कि वातावरण से संबंधित कुछ कॉन्फ़िगरेशन के साथ इसका कुछ संबंध है। मैं अपने application.rb, development.rb की सामग्री और production.rb फ़ाइलों

यहाँ संलग्न कर रहा हूँ यहाँ मेरी production.rb फ़ाइल

# Settings specified here will take precedence over those in config/application.rb 

    # In the development environment your application's code is reloaded on 
    # every request. This slows down response time but is perfect for development 
    # since you don't have to restart the webserver when you make code changes. 
    config.cache_classes = false 

    # Log error messages when you accidentally call methods on nil. 
    config.whiny_nils = true 

    # Show full error reports and disable caching 
    config.consider_all_requests_local  = true 
    config.action_controller.perform_caching = false 

    # Don't care if the mailer can't send 

    #config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
    #config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
    config.action_mailer.delivery_method = :smtp 

    # Print deprecation notices to the Rails logger 
    config.active_support.deprecation = :log 

    # Only use best-standards-support built into browsers 
    config.action_dispatch.best_standards_support = :builtin 

    # Do not compress assets 
    config.assets.compress = false 

    # Expands the lines which load the assets 
    config.assets.debug = true 
end 

module ActiveAdmin 
    class Reloader 
    def attach! 
    end 
    end 
end 

की सामग्री हैं और मेरे development.rb फ़ाइल की सामग्री हैं

# Settings specified here will take precedence over those in config/application.rb 

    # In the development environment your application's code is reloaded on 
    # every request. This slows down response time but is perfect for development 
    # since you don't have to restart the webserver when you make code changes. 
    config.cache_classes = false 

    # Log error messages when you accidentally call methods on nil. 
    config.whiny_nils = true 

    # Show full error reports and disable caching 
    config.consider_all_requests_local  = true 
    config.action_controller.perform_caching = false 

    # Don't care if the mailer can't send 

    #config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
    #config.action_mailer.default_url_options = { :host => 'localhost:3000' } 
    config.action_mailer.delivery_method = :smtp 

    # Print deprecation notices to the Rails logger 
    config.active_support.deprecation = :log 

    # Only use best-standards-support built into browsers 
    config.action_dispatch.best_standards_support = :builtin 

    # Do not compress assets 
    config.assets.compress = false 

    # Expands the lines which load the assets 
    config.assets.debug = true 
end 

module ActiveAdmin 
    class Reloader 
    def attach! 
    end 
    end 
end 

यहाँ मेरी production.rb फ़ाइल की सामग्री हैं

# Settings specified here will take precedence over those in config/application.rb 

    # The production environment is meant for finished, "live" apps. 
    # Code is not reloaded between requests 
    config.cache_classes = true 

    # Full error reports are disabled and caching is turned on 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 

    # Specifies the header that your server uses for sending files 
    config.action_dispatch.x_sendfile_header = "X-Sendfile" 

    # For nginx: 
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' 

    # If you have no front-end server that supports something like X-Sendfile, 
    # just comment this out and Rails will serve the files 

    # See everything in the log (default is :info) 
    # config.log_level = :debug 

    # Use a different logger for distributed setups 
    # config.logger = SyslogLogger.new 

    # Use a different cache store in production 
    # config.cache_store = :mem_cache_store 

    # Disable Rails's static asset server 
    # In production, Apache or nginx will already do this 
    config.serve_static_assets = false 

    # Enable serving of images, stylesheets, and javascripts from an asset server 
    # config.action_controller.asset_host = "http://assets.example.com" 

    # Disable delivery errors, bad email addresses will be ignored 
    # config.action_mailer.raise_delivery_errors = false 

    #config.action_mailer.default_url_options = { :host => 'ha1.heroku.com' } 
    config.action_mailer.delivery_method = :smtp 

    # Enable threaded mode 
    # config.threadsafe! 

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation can not be found) 
    config.i18n.fallbacks = true 

    # Send deprecation notices to registered listeners 
    config.active_support.deprecation = :notify 

    # Compress JavaScripts and CSS 
    #config.assets.compress = true 

    # Don't fallback to assets pipeline if a precompiled asset is missed 
    config.assets.compile = false 

    # Generate digests for assets URLs 
    config.assets.digest = true 

    # Defaults to Rails.root.join("public/assets") 
    # config.assets.manifest = YOUR_PATH 

    config.assets.js_compressor = :uglifier 
    config.assets.css_compressor = :scss 

मैंने 3.1 के लिए रेल दस्तावेज़ों के साथ मेरी कॉन्फ़िगरेशन फ़ाइलों की तुलना की है और ऐसा लगता है कि मेरे पास आवश्यक सभी डिफ़ॉल्ट हैं। हालांकि मैं अभी भी कोई छवि नहीं देख रहा हूँ। किसी भी मदद की बहुत सराहना की जाएगी

उत्तर

13

production.rb से इस लाइन निकालें:

 
config.action_dispatch.x_sendfile_header = "X-Sendfile" 

तुम भी section 9 of the pipeline guides में उन लोगों के साथ अपने config फाइल में सेटिंग्स संरेखित चाहिए।

सेंडफ़ाइल शीर्षलेख में अपस्ट्रीम वेबसर्वर के लिए जानकारी है कि फ़ाइल को खोजने के लिए फ़ाइल (फ़ाइल सिस्टम पर) कहां मिलें। यह बैकएंड (रेल/स्प्राकेट्स) से लोड को हटा देता है। जब HTTP प्रतिक्रिया पर sendfile है कोई शरीर नहीं है (यह शून्य लंबाई है) यही कारण है कि आप कुछ भी नहीं देखते हैं।

Heroku पर nginx सर्वर को एप्लिकेशन फाइल सिस्टम तक पहुंच नहीं है, इसलिए यह काम नहीं करेगा।

Heroku dev site re sendfile पर this note देखें।

यदि आप heroku का उपयोग कर रहे हैं, this document पाइपलाइन प्रभावी ढंग से उपयोग करने के लिए सबसे अच्छे विकल्प को रेखांकित करता है।

+0

मैंने उस रेखा को हटा दिया और यह भी सुनिश्चित किया कि लिंक किए गए पृष्ठ पर उल्लिखित रेखाएं मेरी फाइलों में मौजूद हैं। मेरे पास अभी भी हेरोकू लाइव साइट पर एक ही समस्या है जहां यह छवि नहीं दिखाती है। कोई विचार क्यों? – alik

+1

हम्म वास्तव में, खरोंच है कि, यह अभी काम किया। मुझे लगता है कि यह पहले – alik

+0

कैशिंग कर रहा था आप सही हैं, मेरी समस्या कैशिंग थी। मेरे ब्राउज़र कैश को साफ़ करने के बाद यह ठीक काम करता था। – Ryan

0

आपको इसे हल करने के लिए दो चीजें करने की आवश्यकता है। सबसे पहले, इन दो पंक्तियों को false.rb फ़ाइल में झूठी से सच में बदलें।

 config.assets.compile = true 
     config.assets.digest = true 

दूसरा, अगर आप

 background: image-url("image.jpg") 

अपने चित्रों

background: url("imgo.jpg") 

यह परिवर्तन के लिए इस तरह वाक्य रचना है मुझे आशा है कि यह आपके काम करता है।