简体   繁体   中英

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.

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.

I'm using HAML, SASS and CoffeeScript so my assets need to be compiled. 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. 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. 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.

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.

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. 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.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.

Then in order to make things correct I left it as default, ie, false , but none of my images, stylesheets, or javascripts were loading. 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. Check your public/assets/manifest.yml and compare it with the links on your render text-only page. Using Firebug I saw one interesting thing:

加载资产会返回404错误!

Instead of my application.css , what is being loaded is a 404 page! This gave me the hint that Apache was not being able to reach my public/assets folder.

In order to solve that what I did was to link my public_html/myapp folder to my Rails application assets folder, eg:

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:

<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
  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.

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. But it ended up just being a simple soft link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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