Thin missing css - ruby-on-rails

I'm debugging a Bitnami Rails implementation. I'd like to run Thin instead of Apache to see if my error still shows up.
I go to the Rails app directory using SSH and run this command:
$ thin -e production start
And Thin starts up on 3000. But, when I access using a browser, it looks like none of the CSS is getting used.
Any ideas how I can fix it?
Thanks!
This is what it looks like:

By default Rails does not serve static assets in production.
Usually there is a line
config.serve_static_assets = false
in config/production.rb.
Setting it to true will overwrite the default. If there is no such line, it should be added
If the problems persist, please provide your rails version, and whether you use asset pipeline.

Related

Rails 5 Debug in Production Mode

I am trying to find a way to check logs or debug in production I am using passenger and apache and ubuntu as server. Every time I create any scaffold and upload it to server I get error :
I have used
bundle exec rake assets:precompile RAILS_ENV=production
But getting no success but when I am running application using :
rails s -e production
I can access my controllers and views over port 3000. What is wrong with this why assets:precompile is not working properly I am adding JS files manually not using coffee script. And my javascripts files are not complied.
My question is how can I set anything in production to see a debug like in development mode like this:
Can I do this in production I am using rails 5
The production error you have shown above was a 404 error. it means that the route doesn't exist or there are no controllers methods for that route or is a model not found error.
As for adding debuggers in production, can you do it?
Yes you can.
But should you do it?
NO, because it is a BAD practice. If you wish to view and debug errors in production, check your logs for the stacktrace and work with it from there. As long as it is a rails error, it will be in log/production.log.

rails 4.2 capistrano 3 Ubuntu nginx puma, getting routing error/no assets shows up

After following this tutorial, I tried was able to set up a rails application on an ec2 Ubuntu instance, running nginx web server and puma app server, deployed with capistrano 3. However, none of my assets are showing up, and I'm getting routing errors for basic functions of the Devise gem such as logging out. The chrome dev tool console shows 404 errors for the compiled application.css and application.js files.
I think the assets are there because if I ssh into the instance and go to the folder where my app is, I can see a bunch of files under public/assets. Also, if I check the capistrano logs, I can find the line bundle exec rake assets:precompile, and the status for that is successful. I tried things like going into the production.rb file and changing config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? to config.serve_static_files = true
but still no assets. I think the biggest suspect is that there is some sort of routing error, because I don't really understand how web servers, app servers, and aws instances interact with each other. Could anyone point me in the right direction on debugging this? If you need to see a specific config file please comment below.
Ok it turns out all I had to do is copy the secrets.yml from the local repo for my app to the shared folder that is in [my_app_name]/shared/config. So my app didn't know where to look for the secret key base.
Although I'm still confused on why not having the secret.yml would prevent assets from served...

rails 3 system command not working

Here is the issue. When running the 'system' command in a rails controller in development it behaves as intended by running the command while in production it does not do anything.
For example the following command:
system 'rails g migration user_generated_migration'
or even:
system 'ls'
work locally (in development) but on the server (production environment) they don`t do anything.
Am i missing something in the configuration files, production.rb maybe? Or is there something that should be enabled on the server?
Update:
The production environment is the default set up maybe with a notable change to how caching is handled:
config.cache_store = :dalli_store, ENV['MEMCACHE_SERVERS']
It is running on apache server through passenger. I suspect it has something to do with what rights the apache user has? I don`t have a lot of experience in the server area so i wouldn`t know what exact details to give you.

Custom rails environment log getting written to nginx error.log

I have a custom environment for my app called staging. For some reason, no staging.log file ever gets created, and all of the stuff that I would assume to be written there is instead showing up in the nginx error.log file. Is there a configuration option that I'm missing?
This is an old question, but I just ran into the same issue and wanted to share what fixed it for me in case it helps anyone else who runs into this.
In my case, I was using the rails_12factor gem (because I had my app deployed on Heroku at one point), which causes all logging to go to stdout. This caused it all to get dumped into the nginx_error.log. I was able to completely remove the gem to fix it, since I don't use Heroku for the app any more, but if you need to support Heroku deployment you could add some sort of configuration so that rails_12factor only gets required in that context.
Try adding something like
c = ActiveSupport::BufferedLogger.new("log/staging.log")
c.auto_flushing = true
config.logger = c
to your config/environments/staging.rb
Also you maybe should play with auto_flushing option, rails guide about configuration, says it's turned off in production env, I don't know why. See BufferedLogger docs here.
It doesn't look to me like perfect solution, but looks like it works.
for logging in nginx you have:
the error_log directive, see http://nginx.org/en/docs/ngx_core_module.html#error_log
the acces_log directive, see http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
there's one gotcha with the error_log:
if you have it set to debug, while your nginx is not compiled using the --with-debug flag, it will fallthrough to the default error.log location.
to check if your the flags your nginx was compiled with use the nginx -V command

How to properly diagnose a 500 error (Rails, Passenger, Nginx, Postgres)

I'm having a real tough time diagnosing a 500 error from my application running in production. I've had it working before, but after re-deploying via Capastrano I am unable to get it going.
Here are the facts:
The server is setup with nginx + passenger, and I'm using
PostgreSQL.
Static assets are working properly, as in I'm able to access them just fine in a browser.
I can access the rails console via RAILS_ENV=production bundle exec rails console and perform Active Record actions (like
retrieving data from the db).
Within console, I can run app.get("/"), which returns a 500 error as well (after first showing the query that was run to load
the model).
The production.log file is never written to. I've set permissions 777 on it just for the hell of it. I've also set the log level to
:debug with nothing to show for it.
The nginx log (which passenger also uses) shows no indication of errors, it just notifies about cache misses.
Because nothing of use is being logged, I have no idea what to do here. I've tried setting full permission on the entire app directory with no help. Restarted the server multiple times, nothing. The database is there and rails can clearly communicate with it. I'm not sure what I did to get it to run the first time around. I just don't know why rails isn't outputting anything to the log.
Okay, I figured this out. The app ran fine in development mode, so I knew something production-specific was screwing it up. I went into config/environments/production.rb and changes these settings:
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false # changed from true
config.action_controller.perform_caching = true # changed from false
And then after restarting passenger, rails showed me the error w/ stacktrace. Turns out I was forgetting to precompile the asset pipeline!
Things to check
1) Are you sure you are running in production environment?
Check to see if any entries are in the development.log file
2) Set up your app to email you when a 500 error occurs with a full stack trace. I use the Exception Notifier gem but there are plenty of other solutions for this.
3) When checking your app in the console are you sure you are starting the console in production mode? It is possible that the app is not starting up at all and you just forgot to set the production param thereby thinking that the app runs fine when it doesn't.
4) Are you getting an nginx 500 error or the Rails 500 error? If nginx then it is likely that your app is not starting at all and highly unlikely that you will get any rails error in your log file. The assets are static files and navigating to them proves nothing other than that they exist.
5) Are you sure you are checking the right folder on the server? Sounds really stupid but capistrano could be deploying the app to a folder that is different to the folder that nginx is looking for for your app so double check both the folder capistrano is deploying to and the folder that nginx is looking for are the same.
Just a suggestion, I would use puma rather than passenger. It's awesome with nginx.
My problem is passenger's log file (error.log) has nothing. Then it's a rotation log issue. Run
passenger-config reopen-logs
solved my problem. More.
Have you tried running in development mode to see if the error reports itself?

Resources