如何在开放式换挡轨道中使用资产(How to use assets in open shift rails)

我在openshift rails中部署我的代码,但它没有正确地获取资产。 它既不加载javascripts也不加载图像。 如何使它工作?

I was deploying my code in openshift rails but it did not take the assets properly. It's neither loading the javascripts nor the images. How to make it work?

最满意答案

您要检查的第一件事是您的应用程序中是否存在资产。 此脚本在build.sh脚本(下面提到)之前运行。 它试图为你的public/assets文件夹创建一个符号链接( 这是这背后的原因 )。 即使你有那个目录, rake任务仍然有效; 每次推动都会消除资产。

每当您推送到git存储库时,您的资产都应该进行编译。 这是由Ruby 1.9盒式磁带中的这个脚本处理的(这是由服务运行的,你无法控制它)。 正如您所看到的,它将运行bundle exec rake assets:precompile只要您拥有Gemfile就可以bundle exec rake assets:precompile (对于所有Rails应用程序应该是这种情况)。

.openshift/action_hooks ,你要做的第一件事就是检查.openshift/action_hooks以确保你没有运行任何可能覆盖你的public/assets目录的东西。 你可以将它们与这里的那些进行比较。

接下来你要做的就是检查OpenShift主机上的目录。 您可以通过SSH连接到您的应用程序来执行此操作 ( 说明在此处 )。 然后检查您的public/assets目录。 注意:某些输出已缩短....

# First we make sure it is a symlink. > file $OPENSHIFT_REPO_DIR/public/assets ..../app-root/runtime/repo/public/assets: symbolic link to `..../data//assets' # Then we see if there is anything in it > ls $OPENSHIFT_REPO_DIR/public/assets .... (should have a bunch of.js, .css, etc files)

如果该目录为空,则可能是编译资产时出现问题。 当你git push时你应该注意输出,看看是否有任何失败的迹象(你可能想要使用tee捕获输出: git push 2>&1 | tee git_push.log )。 如果目录中有资产,请按照以下步骤检查日志。

如果您仍然遇到问题,可以通过我们的IRC频道来解决 ,有人应该能够亲自帮助。

The first thing you will want to check is if the assets exist on your application. This script is run before the build.sh script (mentioned next). It attempts to create a symlink for your public/assets folder (here is the reasoning behind this). Even if you had that directory, the rake task would still work; the assets would just be wiped every push.

Your assets should be compiling whenever you push to your git repository. This is taken care of by this script in the Ruby 1.9 cartridge (this is run by the service and you have no control over it). As you can see, it will run bundle exec rake assets:precompile as long as you have a Gemfile (which should be the case for all Rails apps).

With all that being said, the first thing you should do is check your .openshift/action_hooks to make sure you are not running anything that might be overwriting your public/assets directory. You can compare them against the ones here.

The next thing you should do is actually check the directory on your OpenShift host. You can do this by SSHing into your app (instructions are here). Then check your public/assets directory. Note: Some of the output has been shortened with .....

# First we make sure it is a symlink. > file $OPENSHIFT_REPO_DIR/public/assets ..../app-root/runtime/repo/public/assets: symbolic link to `..../data//assets' # Then we see if there is anything in it > ls $OPENSHIFT_REPO_DIR/public/assets .... (should have a bunch of.js, .css, etc files)

If that directory is empty, maybe there is a problem with compiling the assets. You should pay attention to the output when you git push and see if there is any indication that it is failing (you may want to capture the output using tee like: git push 2>&1 | tee git_push.log). If there are assets in the directory, check your logs by following these steps.

If you're still having problems, swing by our IRC channel and somebody should be able to help in person.

更多推荐