0
votes

My Rails 4 application runs in development mode, but at production I only see an empty page.

It's running Unicorn with Nginx in a CentOS 7 VPS.

Any hint what I need?

unicorn_rails -c config/unicorn.rb -D

Rails development

unicorn_rails -c config/unicorn.rb -D -E production

Rails production

The logs of Nginx, Unicorn and Rails don't show any errors.

Rake routes
[root@mycentos my_app]# rake routes

   Prefix Verb   URI Pattern               Controller#Action
    blogs GET    /blogs(.:format)          blogs#index
          POST   /blogs(.:format)          blogs#create
 new_blog GET    /blogs/new(.:format)      blogs#new
edit_blog GET    /blogs/:id/edit(.:format) blogs#edit
     blog GET    /blogs/:id(.:format)      blogs#show
          PATCH  /blogs/:id(.:format)      blogs#update
          PUT    /blogs/:id(.:format)      blogs#update
          DELETE /blogs/:id(.:format)      blogs#destroy

In development I can access normally to any route, even it shows me error messages when the route doesn't exist. But in production, is always blank. Works well in development - always blank in production

2
What is the output or error if you run rake routes on the production server?Elvn
And, did you run $ rake assets:precompile RAILS_ENV = production prior to upload and deployElvn
No I haven't run it before. The app is generated in the same VPS, not uploaded.Ricardo Castañeda
After running rake assets, what else must I do?Ricardo Castañeda
Not sure. Need more info. What does running 'rake routes' on the production server output?Elvn

2 Answers

2
votes

After investigating a lot, the problem was that there wasn't the secret key for production. So I had to generate it running rake secret and pasting it in config/secrets.yml.

1
votes

I'm not so boldly switching over to the answer area here, but it's time. I know that node.js can be used to create a single page app on Rails. It's something I want to try, but haven't done, yet.

Before diving into an isolate and conquer scenario, have you looked at your production log. It will probably be stacked up with errors. Do they tell you anything?

I approach this not knowing exactly the complexion of the problem. And, I don't know what you've already tried. But, I would try to isolate the problem by removing components and complexity. I suggest creating a very simple "Hello world" page at the root. That's it. If we can resolve this and get something to deploy, then you can progress.

Getting a "Hello world!" page will prove your MVC code base setup and deploy are functioning. And you isolate the database out as a variable in production.

Hello world! Simple test - I have not seen a Rails app which did not require a root_url. (maybe node.js setup does not req. one? Dunno.) In your routes.db add

  root 'static_pages#home'

Rake in and make sure the path shows up. Create an home.html.erb in /static pages that has html for "Hello World." Deploy + test to dev + prod using the same command you've been using:

unicorn_rails -c config/unicorn.rb -D -E production

If working, then you know that your deploy works, If not working in production, then remove another component...

Unplug Node.js

In your simple "Hello Page" world app, you don't need node.js. If you are 100% confident it can't be introducing the problem, then disregard this advice.

Hello world, Still not working without database and without node.js? Look at production parameters, Gemfile, etc. I'll add detail here if needed. Although I hope the problem isn't in the environments/production.rb...but it could be.


It would seem like someone with Rails exp. on node.js would be better to answer this question, but since no one else is stepping up, I hope my input is of some help, if only to see the problem in another way.