将Rails App作为子目录运行时,将“/”重定向到“/ sub-directory”?

时间:2017-04-26 18:32:14

标签: ruby-on-rails ruby ruby-on-rails-4 deployment routes

我正在运行我的rails应用程序作为子目录(出于apache映射的原因):

config.ru:

map '/sub-directory' do
    run Rails.application
end

application.rb中:

config.root_directory = "/sub-directory/"
config.action_controller.relative_url_root = '/sub-directory'

所以现在我的应用程序(它的根目录)是从路由http://localhost:3000/sub-directory运行的。问题是,当我转到http://localhost:3000/时,我得到了页面:

Not Found: /

我知道我得到的是因为我的应用程序不再在那里运行,但我希望该路由重定向到http://localhost:3000/sub-directory。无论如何我能做到这一点吗?

如果这有帮助,routes.rb:

require 'resque/server'
Rails.application.routes.draw do

  get "handle/:handle" => "handles#index"
  get "/tag/:hashtag" => "tags#index"

  get "handles/:handle" => "handles#index"
  get "/tags/:hashtag" => "tags#index"

  devise_for :users, :controllers => {
    :registrations => "registrations",
    :passwords => "passwords"
  }

  devise_scope :user do 
    get "/email" => "registrations#email"
    post "/registrations/check_email" => "registrations#check_email"
    get "/users/sign_in" => "registrations#signup"
  end



  authenticated :user do
    devise_scope :user do
      root :to => redirect("app"), as: :authenticated_root
      get "/app", :to => 'reports#index'
    end
  end

  unauthenticated do
    devise_scope :user do
      root to: 'registrations#new'
    end
  end

  get '/oauth' => 'social_platforms#new'

  get "/auth/:provider/callback" => "social_platforms#create"

  get   '/login', :to => 'sessions#new', :as => :login

  # match '/auth/failure' => 'sessions#failure', :via => [:get]

  # get '/reports', to: 'pages#reports', as: :reports
  resources :reports, only: [:show, :index]
  get '/get_report', to: 'reports#get_report'
  get '/check_token', to: 'reports#check_token'

  mount Resque::Server.new, at: "/resque"

  get '*path' => redirect('/')
end

0 个答案:

没有答案