简体   繁体   English

Site5上乘客中的Rails 3没有资产正在加载

[英]Rails 3 in Passenger on Site5 no assets are loading

I wrote an app in Rails 4 and got hosting through Site5 who like many others only has Rails 3.2 and Ruby 1.8.7 with Phusion Passenger. 我在Rails 4中编写了一个应用程序,并通过Site5进行了托管,Site5与许多其他人一样仅在Phusion Passenger中使用Rails 3.2和Ruby 1.8.7。

I have been slowly re-coding the site to work with these ancient requirements but have hit a brick wall with the asset pipeline. 我一直在缓慢地重新编码站点以使其符合这些古老的要求,但在资产管道方面却遇到了障碍。 None of my css, javascript or images shows up since the assets folder is not in the public folder. 我的css,javascript或图像都没有显示,因为资产文件夹不在公用文件夹中。

I'm using HAML, SASS and CoffeeScript so my assets need to be compiled. 我正在使用HAML,SASS和CoffeeScript,因此需要对我的资产进行编译。 My app's original structure looked like this: 我的应用程序的原始结构如下所示:

- app
|- assets
||- images
||- javascripts
||- stylesheets
...
- public
|- .htaccess
|- assets

Though my links and text appeared, I didn't get any images, javascript, stylesheets, etc. Through many useless tech support sessions with Site5 (who literally don't know anything about Rails) I realized I might have to restructure my app because all Apache or Passenger is expecting assets in the public_html folder. 尽管我的链接和文本出现了,但是我没有得到任何图像,JavaScript,样式表等。通过与Site5进行的许多无用的技术支持会议(他们对Rails完全一无所知),我意识到我可能必须重组应用程序,因为所有Apache或Passenger都希望在public_html文件夹中拥有资产。 So I tried softlinking my assets to the public folder to no avail. 因此,我尝试将资产自动链接到公用文件夹无济于事。 Then I just copied them like so: 然后我像这样复制它们:

- app
|- assets
||- images
||- javascripts
||- stylesheets
...
- public
|- .htaccess
|- assets
|- images
|- javascripts
|- stylesheets

Now my images show up but without any styling, javascripts, nothing. 现在,我的图像出现了,但是没有任何样式,javascript,什么也没有。 I've tried running 我试过跑步

RAILS_ENV=production bundle exec rake assets:precompile

I've looked at many posts about passenger and rails but it doesn't seem to give answers about the assets. 我看过许多有关乘客和铁路的文章,但似乎没有给出有关资产的答案。 I've also read a lot about Rails assets pipeline but that doesn't seem to give any insight as far as Passenger is concerned. 我也阅读了很多有关Rails资产管道的信息,但是就乘客而言,这似乎并没有提供任何见识。

I'm really stuck and getting very frustrated because it seems that since both Dreamhost and Site5 run on old versions of Rails, more people would have coded the site before realizing that they're version is too new. 我真的很困惑,也感到非常沮丧,因为似乎Dreamhost和Site5都在旧版本的Rails上运行,因此更多的人会在对该站点进行编码之前意识到它们的版本太新了。

Any help would be useful. 任何帮助将是有用的。

This questions is a bit old, but recently I've faced the very same problem. 这个问题是有点老了,但最近我遇到了同样问题。 The difference here is that I am on Bluehost instead of Site5. 这里的区别是我在Bluehost上而不是Site5上。 Here I will put what are the options to make it work, those that I've tested on mine, which ended up solving the problem. 在这里,我将介绍使它起作用的选项,这些都是我在我的测试中最终解决的问题。

First thing that I saw in the suggestions when I was looking for this problem is that in the /config/environments/production.rb it should be 在寻找此问题时,在建议中看到的第一件事是,在/config/environments/production.rb应该是

config.serve_static_assets = false 

which is the default option. 这是默认选项。 Before that I set as true , which was the only way it could work, but Rails would compile the assets and it was hitting hard the performance. 在此之前,我将其设置为true ,这是它可以工作的唯一方法,但是Rails会编译资产,并且会严重影响性能。

Then in order to make things correct I left it as default, ie, false , but none of my images, stylesheets, or javascripts were loading. 然后,为了使情况正确,我将其保留为默认值,即false ,但未加载任何图像,样式表或javascript。 It was a old-school text-based page, not good. 这是一个老式的基于文本的页面,不好。

The assets were correct on my public/assets folder, and looking on the page I saw that the links were correct, ie, the generated HTML was looking for the correct compiled files. 这些资源在我的public / assets文件夹中是正确的,并且在页面上看到链接是正确的,即生成的HTML正在寻找正确的编译文件。 Check your public/assets/manifest.yml and compare it with the links on your render text-only page. 检查您的public/assets/manifest.yml ,并将其与您的渲染纯文本页面上的链接进行比较。 Using Firebug I saw one interesting thing: 使用Firebug,我看到了一件有趣的事情:

加载资产会返回404错误!

Instead of my application.css , what is being loaded is a 404 page! 而不是我的application.css ,正在加载的是404页面! This gave me the hint that Apache was not being able to reach my public/assets folder. 这给了我暗示Apache无法访问我的public / assets文件夹。

In order to solve that what I did was to link my public_html/myapp folder to my Rails application assets folder, eg: 为了解决我所做的就是将我的public_html/myapp文件夹链接到我的Rails应用程序资产文件夹,例如:

ln -s /home2/my_dir_at_bluehost/rails/app_at_bluehost/public/assets /home2/my_dir_at_bluehost/public_html/app_at_bluehost/assets

And it finally worked. 终于奏效了。 Bellow is the .htaccess that works with that that on Bluehost: 波纹管是与Bluehost上的.htaccess一起使用的.htaccess:

<IfModule mod_passenger.c>
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
RailsEnv production
RackBaseURI /
PassengerAppRoot /home2/my_dir_at_bluehost/rails/app_at_bluehost
SetEnv GEM_HOME /home2/my_dir_at_bluehost/ruby/gems
</IfModule>

To summarise: 总结一下:

  1. Check if the config.serve_static_assets = false 检查config.serve_static_assets = false
  2. Check if the page is presenting the correct links to the compiled assets 检查页面是否显示指向已编译资产的正确链接
  3. Check with Firebug what is the content of the CSS being loaded, if it is the 404 page, just link the assets folder to your public_html folder. 使用Firebug检查正在加载的CSS的内容是什么,如果是404页面,只需将资产文件夹链接到您的public_html文件夹。

Even contacting support on Bluehost was not satisfatory as yours on Site5, they told me if I wanted I could go for a VPS that no global configuration can be done on shared hosting. 他们甚至告诉我,如果我希望我可以使用VPS,那就是在共享主机上无法进行全局配置,就连在Bluehost上与Bluehost上的支持联系都不能令人满意。 But it ended up just being a simple soft link. 但这最终只是一个简单的软链接。

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

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