Rails Production server stylesheet not loading - ruby-on-rails

I am using the digital ocean ruby on rails image which has nginx and unicorn. I bundled my project bundle install and then did service unicorn restart but it doesnt seem to be loading. I had this issue a while ago and solved it using bundle exec ... but I cant remember the full command. I saw a few issue similar to this and tried bundle exec rake assets:precompile as well as editing the production.rb (Why "rails server -e production" makes it "No route matches "/" and stylesheet not loading?) file but it does not work. I am looking for the solution to do this through the command and not through code.
EDIT: bundle exec rake assets:precompile did somewhat work! The problem is that I created an extra css file called main.css which isnt importing, but everything else works!

Use RAILS_ENV=production rake assets:precompile. RAILS_ENV=production specifies the environment in which you run your rake tasks.

Related

rails4 rake assets precompile in production environment generate wrong javascript file

I'm working on deploy my rails application and I found that error always exists in my javascript file when I run RAILS_ENV=production bundle exec rails assets:precompile.But when I run rails assets:precompile to generate js file, it works well.Is there any differences between production and development in precompile phase? How can I solve this problem?
I think you don't have permission to generate compiled javascript file, to trace your error, run the following command:
RAILS_ENV=production bundle exec rails assets:precompile --trace
Solution of permission issue:
Try to run the command as sudo as the following:
sudo RAILS_ENV=production bundle exec rails assets:precompile --trace

rails assest:precomplie , when load file not correct

I have web RoR, I ran assets:precomplie, and i got file
**/application-dfaaca6b25e0d101d80f81c5cb194f6d39d331886613c0a392283b01b9911cb0.css**
but my web was loaded another file
**application.self-a429e1a197d1ad3e5a775f50a60fd344db3ba490db151ab8c7494a78cba792a2.css**.
i don't know reason. Anybody, can help me? Thanks a lot
I got the same questions. then finally I find the answer:
when you process assets:precomplie, you must specify the env as you run rails, because in different enviroments, the assets version is not same!
when you run rails in development env as rails s, you should process as rake assets:precomplie or assets:precomplie RAILS_ENV=development
when you run rails in production env as rails s -e p, you should process as rake assets:precomplie RAILS_ENV=production
hope this helps!
Solution:
Deploy your application again
if still not solved
SSH into the system
delete the file your_app/manifest_backup
$ bundle exec rake assets:clear
$ bundle exec rake assets:precompile RAILS_ENV=production
restart the webserver ( for Nginx /etc/init.d/nginx restart or $ sudo service nginx restart )
if still not solved deploy your app again
For more info see my blog
https://cbabhusal.wordpress.com/2015/07/20/ruby-on-rails-production-staging-when-asset-path-is-outdated/

Delayed Job in Rails 4 with Capistrano

I cant figure how to start Delayed Jobs on a dedicated Ubuntu server.
It works fine on my localhost but when I run on my server
sudo RAILS_ENV=production bin/delayed_job restart
I get
sudo: bin/delayed_job: command not found
On top of that, if I run the "rake jobs:work RAILS_ENV=production" command Im getting the following error:
PG::FeatureNotSupported: ERROR: SELECT FOR UPDATE/SHARE is not allowed in subqueries
Apparently theres an issue with my psql version.
Is there any way I can get the script to work? Any effective Capistrano recipes available? All ive found on the web are old recipes for Rails 3 and older versions of capistrano.
Thanks in advance.
EDIT:
I have already bundled install the daemons gem and generated "delayed_job:active_record" on my local machine, then proceded to cap deploy which bundle installed and migrated in the production server.
The bin/delayed_job file exists in the server yet it fails with command not found.
And add this to config/environment.rb:
ENV['RAILS_ENV'] ||= 'production'
Then at your production server:
RAILS_ENV=production rake db:migrate
RAILS_ENV=test production generate delayed_job:active_record && RAILS_ENV=production rake db:migrate
Now after you do that:
RAILS_ENV=production script/delayed_job start
As for Capistrano error you are facing, please try to add the command like:
run "cd #{current_path}; #{sudo} RACK_ENV=production bundle exec #{current_path}/bin/delayed_job start"
You must run this on target server:
bundle exec rails generate delayed_job

Solr Sunspot Production environment setup issue

I am trying to setup solr sunspot search in production mode.
I have followed the below tutorial and got success in setting up tomcat-solr server running.
http://www.arborisoft.com/how-to-install-apache-solr-4-4-on-ubuntu-12-04/
I ran
rails generate sunspot_rails:install
and configured the config/sunspot.yml file.
For development mode I used 'sunspot_solr' gem(which is not advisable for production mode) and got this command working.
bundle exec rake sunspot:solr:start
When I removed this gem
it's giving me following error
Note: This task has been moved to the sunspot_solr gem. To install, start and
stop a local Solr instance, please add sunspot_solr to your Gemfile:
group :development do
gem 'sunspot_solr'
end
I have tried adding this to Rakefile:
require 'sunspot/solr/tasks'
when I run the following command
bundle exec rake app:sunspot:solr:start
I am getting the following error
rake aborted!
cannot load such file -- sunspot/solr/tasks
I am using rails 4.
I don't know what I've missed. I have searched for the solution in and out of stackoverflow. But I couldn't get any reference. Even if I find any since I am a rails noob, I couldn't understand what they are talking about. any solution will be really helpful.
You can also change the path to solr/default in config/sunspot.yml file for production mode or any other defined modes.
These are some terminal commands which could follow to solve your problems:
ps aux | grep solr to get solr process ID
through this you can check which server id is running and which one is in your sunspot pid file.
sudo kill <ID>, <ID> is the ID you found from 1
rm -r <path/to/solr>, remove the solr directory inside your project to remove all of previous indexes
RAILS_ENV=production bundle exec rake sunspot:solr:start
Change the path to /solr/default inside config/sunspot.yml
RAILS_ENV=production bundle exec rake sunspot:solr:reindex
this link can also help in understanding problem and issues:https://github.com/sunspot/sunspot/issues/492

Assets in Rails 4

I've updated my Rails 3.2 app to 4.0 version and have stumbled upon one problem.
When I run the site with config.assets.compile = false option it doesn't load any assets. I've tried rake assets:precompile and it compiles assets at public/assets, but site doesn't load any of those. I've got application.js and application.css included in my layout, but when I check the source of the page, it's said that they are not found.
When I run the site with config.assets.compile = true everything works perfectly, but I've read that turning this off will result in greater performance, so I need to get it work.
Thanks in advance.
UPD: I've found that if I'm using this command RAILS_ENV=production bundle exec rake assets:precompile everything works. The question is why the rake assets:precompile command doesn't working?
UPD2: For those, who have the same issue, here's the explanation.
Regular rake assets:precompile compiles assets for application that runs in development mode. Specifying RAILS_ENV=production part in the beginning makes the command to compile assets for production mode, the bundle exec part is not required. So the final command looks like this: RAILS_ENV=production rake assets:precompile. Maybe it was obvious, but it took me a while to understand. Thanks.

Resources