简体   繁体   English

Rails 3无法从Apache服务器提供生产资产

[英]Rails 3 cannot serve assets in production from apache server

Using Rails 3.2.2 and ruby 1.9.2 and I am not able to serve assets in production. 使用Rails 3.2.2和ruby 1.9.2,我无法在生产中使用资产。 Not really experienced in configuring servers for webapps. 没有真正为Webapp配置服务器的经验。

I have the following code in applictation.html.erb, 我在applictation.html.erb中有以下代码,

  <a href="/"><img src="/assets/topbar.png" border="0" alt="My LOGO"></a>

I put topbar.png in app/assets/images/. 我把topbar.png放在app / assets / images /中。 It works as expected in development mode, shows up when the png is there, does not show up if I delete the png. 它在开发模式下按预期工作,当png存在时显示,如果删除png则不显示。

It does not show up in production. 它不会出现在生产中。 We have done the following, so far. 到目前为止,我们已经完成了以下工作。 The app does run, but it does not show the above asset. 该应用程序可以运行,但不会显示上述资产。

<VirtualHost *:8081>
  ServerName dev.mycompany.com:8081
        DocumentRoot /var/www/vhosts/dev.mycompany.com/webapps/
#        PassengerAppRoot /var/www/vhosts/dev.mycompany.com/webapps/testapp/public
#   PassengerLogLevel 3

        RackBaseURI /myRailsTest
        <Directory /var/www/vhosts/dev.mycompany.com/webapps/myRailsTest>
                AllowOverride all
                Allow from all
                Options -MultiViews
            <IfModule mod_php5.c>
                    php_admin_flag engine on
                    php_admin_flag safe_mode on
             </IfModule>
        </Directory>
</VirtualHost>

Do I have to do something more to configure the apache server? 我是否需要做更多的事情来配置apache服务器? I'm reading this: http://guides.rubyonrails.org/asset_pipeline.html , but finding it pretty dense for a newbie. 我正在阅读: http : //guides.rubyonrails.org/asset_pipeline.html ,但是对于新手来说,它显得很密集。

What can I try? 我可以尝试什么? One thing I read is: "You should use app/assets for files that must undergo some pre-processing before they are served. In production, Rails precompiles these files to public/assets by default." 我读到的一件事是:“对于应在提供服务之前必须经过一些预处理的文件,应该使用应用程序/资产。在生产中,Rails默认将这些文件预编译为公共/资产。” But actually, I can't see that it is doing that for me. 但实际上,我看不到它正在为我做这件事。 Is that the problem? 那是问题吗? Thanks! 谢谢!

Check out this section of rails guides: http://guides.rubyonrails.org/asset_pipeline.html#in-production 查阅本节Rails指南: http : //guides.rubyonrails.org/asset_pipeline.html#in-production

Basically, you have 2 options: 基本上,您有2个选择:

  1. Precompile your assets with bundle exec rake assets:precompile 使用bundle exec rake assets:precompile
  2. Live compilation: config.assets.compile = true 实时编译: config.assets.compile = true

And you should use image_tag to create <img> helper in your layouts and views, because during the precompilation phase an MD5 is generated from the contents of the compiled files, and inserted into the filenames as they are written to disc. 而且,您应该使用image_tag在布局和视图中创建<img>帮助器,因为在预编译阶段,会从已编译文件的内容中生成MD5,并将其插入到写入磁盘的文件名中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM