Production Rails app fails with almost no log - ruby-on-rails

I did my first deploy with a very simple rails app today on a Digital Ocean droplet running Ubuntu 14.04. I deployed following this article
https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
and only replaced RVM with rbenv.
Now I get the "We're sorry, but something went wrong." Rails error page. My production.log says the following:
D, [2016-02-13T15:58:41.165515 #1783] DEBUG -- : ^[[1m^[[36mActiveRecord::SchemaMigration Load (1.5ms)^[[0m ^[[1mSELECT "schema_migrations".* FROM "schema_migrations"^[[0m
Puma logs are clean though. I had some trouble with rake in the first place, as migrations weren't executed by capistrano itself. So I updated rake from 10.4.2 to 10.5 and executed the migrations manually, but still the same error. Thanks in advance.
EDIT:
What I just noticed is that my public folder looks like this:
404.html 422.html 500.html assets favicon.ico robots.txt
As this is nginx' root folder, how is the app supposed to load in any way? As I said, this is my first deploy.

Puma logs are clean, but I bet Rails ones aren't. They're located under RAILS_ROOT/log directory, you probably want the production one.
My guess, without seeing those logs are that it's one of the following, ordered by likelihood:
You do not have a secret token generated which is done using rake secret and placing it in an environment variable. Check config/secrets.yml.
Bad database connection
Ruby environment is wrong, a certain gem is missing
It should be one of these three things. Check the log file first, though and maybe post it as an edit

Rails is letting you know that migrations need to be run by trying to load the schema so:
RAILS_ENV=production rake db:migrate assets:precompile

Related

Capistrano Nginx Rails, After Rake Db:Migrate "Something went wrong"

I needed to migrate my database, so I made the changes to my local system, pushed them to git, then cap production deploy. Once on the service I went to the current and ran rake db:migrate. Now when I visit my site I receive an error We're sorry, but something went wrong (500). There is no other information and my /opt/nginx/logs/error.log is completely blank. How do I fix this?
I'm using Postgresql, capistrano, rails 3, nginx
If you correctly installed ruby, rails, passenger and nginx, then follow my gist. You should go through the files and change the configuration according to your need. Here, you'll find
Gemfile // required gems for capistrano deployment
Capfile
deploy.rb // change the configuration for your server
production.rb // change the configuration for your server
After fully configured according to the gist, run
cap production deploy:check # it'll tell you what is missing for deploying your application
then, cap production deploy
Always check the production.log file if you facing any problem.

Rails - Can I run rake assets:precompile on production server, while the production app is still running?

Sorry if this question sounds basic. But I haven't been able to find an answer anywhere on the web...
I'm currently running my Rails app on a Ubuntu server. Until now I've always shut down the production app before I pull the changes, run rake assets:clean assets:precompile, and only boot up the Rails app again once the process is finished.
I'm not sure whether the shutting down of app is necessary(i.e. if I don't do it, my app will behave erratically). It induces about 5 minutes of down time.
If that's a must, then maybe I should try to do local precompilation/more advanced deployment procedure, in order to reduce downtime? (Tried local compilation according to http://guides.rubyonrails.org/asset_pipeline.html#local-precompilation, but then after deleting original public/assets and pulling locally precompiled public/assets from the repo, the production server was having rack timeout all the time and won't render anything.)
YES you run rake assets:precompile Rails looks through your assets folder and copies over everything that is not Javascript or CSS into public/assets. It then creates application.js by reading app\assets\javascripts\application.js, and application.css by reading app\assets\stylesheets\application.css, loading up all the "require" files it finds in there.
So yes..you can do it ..but if you ran rake assets:clean..and then precompile...then public/assets will be updated with new compiled assets.
Dont forget to restart the server :)

How to precompile Ruby on Rails website into Production Mode?

I have locally made this website on my local Linux Debian 6 under path /HOME/ADMIN/WWW/WEBSTUDIO and I need it to be published on my virtual server.
Is "precompiling" the actual word? I know about the command 'rails server' but that is clearly not the same thing as it makes no alterations on the PUBLIC folder.
I guess I have to first transfer my directory structure to server (has Apache2 and ISPCONFIG3 already) and I have done everything so far as how it is described here, but it doesn't tell how to put and precompile your site into Prod Mode.
So what's the procedure? ONLY the basic steps.
When you run rails server or rails s for short your start the rails server
The precompilation isn't for the code, it's for the assets (css,js,fonts, images, etc), rails compiles all css and js each to a single file to reduce the number of http requests needed to load the site.
Also if you are using scss, less or any of those files that need processing it would be done during the precompilation, and if any gems contain assets it would be copied to the public folder.
The precompilation command as mentioned in other answers/comments is
rake assets:precompile
On server terminal, from the root of the project, run:
RAILS_ENV=production rake assets:precompile

Welcome aboard ActiveRecord::ConnectionNotEstablished

I'm using Ubuntu, with Rails 3.0.1 with mysql2 socket.
When i do runing install, rake db:create and after rails server, my Welcome aboard, shows ActiveRecord::ConnectionNotEstablished in About your application’s environment
What i do?
Had the same problem on rails 3.1.1:
rake db:create - ok
rails console and some DMLs - ok
but accessing info from the web-page resulted in ActiveRecord::ConnectionNotEstablished.
A rails server restart helped.
It sounds like your MySQL server isn't running. You'll need to install MySQL if you haven't already (apt-get install mysql-server should do it). Once it's running, you'll need to set up a user and database for your app, and note the username and password so that you can put that information in config/database.yml within your app.
This link will be useful if you need any help with those steps.
You'll need to do some more debugging to work it out.
How are you running your server?
Make yourself a model.
rails generate model Something name:string
Then try running rake db:migrate
Does this work?
If it does, then you must be running your server in a different way (maybe you're running it in production mode?)
Try rails console and try to do Something.count
If all of those work
then I'd suggest you try restarting your server.
rails server

How to get rails admin working on production server?

Rails_admin works on my development server with port :3000,
but not working on production server, responds 404 error!
How to get it working on production server ?
Thanks
Have you tried running the following?:
$ rake rails_admin:copy_assets
Spotted this little bit in the GitHub ReadMe:
When running RailsAdmin in production the images, stylesheets,
and javascript assets may return 404
not found error's depending on your
servers static assets configuration.
To prevent this issue you can copy
assets directly into your application
by running:
$ rake rails_admin:copy_assets
I had to do a RAILS_ENV=production bundle exec rake db:reset, then it worked. Don't know whether it was a user session issue (no privileges?) or something else.
Be careful though not to execute the command above if you have "real" data in your database!

Resources