Using Rails 3.2.2 and ruby 1.9.2 and I am not able to serve assets in production. Not really experienced in configuring servers for webapps.
使用Rails 3.2.2和ruby 1.9.2,我无法在生产中提供资产。在为webapps配置服务器方面没有经验。
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/. It works as expected in development mode, shows up when the png is there, does not show up if I delete the png.
我把topbar.png放在app / assets / images /中。它在开发模式下按预期工作,在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? I'm reading this: http://guides.rubyonrails.org/asset_pipeline.html, but finding it pretty dense for a newbie.
我是否还需要做更多的事情来配置apache服务器?我正在读这篇文章: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." But actually, I can't see that it is doing that for me. Is that the problem? Thanks!
我该怎么办?我读到的一件事是:“你应该将app / assets用于必须在服务之前进行一些预处理的文件。在生产中,Rails默认将这些文件预编译为public / assets。”但实际上,我看不出它对我这样做了。这是问题吗?谢谢!
1 个解决方案
#1
1
Check out this section of rails guides: http://guides.rubyonrails.org/asset_pipeline.html#in-production
查看导轨指南的这一部分:http://guides.rubyonrails.org/asset_pipeline.html#in-production
Basically, you have 2 options:
基本上,您有两个选择:
- Precompile your assets with
bundle exec rake assets:precompile
- 使用bundle exec rake资产预编译资产:预编译
- 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在布局和视图中创建帮助器,因为在预编译阶段,MD5是从编译文件的内容生成的,并在写入光盘时插入到文件名中。
#1
1
Check out this section of rails guides: http://guides.rubyonrails.org/asset_pipeline.html#in-production
查看导轨指南的这一部分:http://guides.rubyonrails.org/asset_pipeline.html#in-production
Basically, you have 2 options:
基本上,您有两个选择:
- Precompile your assets with
bundle exec rake assets:precompile
- 使用bundle exec rake资产预编译资产:预编译
- 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在布局和视图中创建帮助器,因为在预编译阶段,MD5是从编译文件的内容生成的,并在写入光盘时插入到文件名中。