2

I have a Rails server where nginx routes / to /api, and I have rails_admin gem installed. I can access the admin panel at /api/admin, but all the models listed on the admin page link to /admin/:model. I can't seem to find a way to get the links to route to /api/admin/:model instead.

I have set the following in application.rb:

config.relative_url_root = "/api"
config.action_controller.relative_url_root = "/api"
ENV['RAILS_RELATIVE_URL_ROOT']  = "/api"
ENV['ROOT_URL']  = "/api"

But the admin page links have not changed.

If I change routes.rb to have rails_admin under a namespace, the problem is not fixed: the admin page now becomes api/api/admin and the links go to api/admin/:model, but with the routes it requires api/api/admin/:model instead.

How can I fix this?

txie1993
  • 21
  • 2

1 Answers1

0

UPDATE: This answer may help you if you actually want to add /api for whole rails app, not only rails_admin.

You do not need those configs in your application.rb for it. Read this doc: https://www.phusionpassenger.com/library/deploy/nginx/deploy/ruby/

Here's example of my configs:

server {
  listen 80 default_server;
  server_name www.mydomain.com;
  root /var/www/AppName/current/client/dist;
  error_page 404 =200 /index.html;
  location ~ ^/api(/.*|$) {
    alias /var/www/AppName/current/public$1;  # <-- be sure to point to 'public'!
    passenger_base_uri /api;
    passenger_app_root /var/www/AppName/current;
    passenger_document_root /var/www/AppName/current/public;
    passenger_enabled on;
    passenger_app_env production;
  }
}

P.S. here's the explanation for error_page 404 =200 /index.html; - Angular 2.0 router not working on reloading the browser

Community
  • 1
  • 1