首页 > 解决方案 > Rails 应用程序无法在 Heroku 上加载根路径“/”

问题描述

在将我的 Rails 应用程序部署到 Heroku 后,我收到以下消息“您正在寻找的页面不存在”。它在我的本地主机上运行得很好,只是在 Heroku 上出现了问题。

我确保heroku run rake db:migrate在 routes.rb 中运行并将我的根设置为root 'welcome#index'

当我在rake routes本地运行时,我得到以下(不是完整列表)

    Prefix Verb          URI Pattern         Controller#Action                                                                       
         root GET     /                  welcome#index                                                                              
welcome_index GET    /welcome(.:format)  welcome#index 

运行时根路径明显丢失heroku run rake routes

Prefix Verb                        URI Pattern                                                                          Controller#Action                                                                  
rails_service_blob        GET  /rails/active_storage/blobs/:signed_id/*filename(.:format)                               active_storage/blobs#show
rails_blob_representation GET  /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show

Heroku 日志显示以下内容: 2020-06-25T01:46:58.550276+00:00 app[web.1]: F, [2020-06-25T01:46:58.550205 #4] FATAL -- : [b01338d3-12f9-486c-8b05-0f7e525d01ba] ActionController::RoutingError (No route matches [GET] "/"):

我还删除了我的 Heroku 应用程序并从头开始。我似乎无法弄清楚为什么我的根路径没有被识别。

添加Routes.rb文件内容

Rails.application.routes.draw do
  root 'welcome#index'
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

end

标签: ruby-on-railsheroku

解决方案


推荐阅读