ruby-on-rails - 无法找到 Rails/Heroku : "The page you were looking for doesn' t exist"的解决方案

标签 ruby-on-rails ruby heroku

我不久前注册了一个月的 Rails 计划,现在才开始参加。我已经安装了 Rails,设置了 GitHub 和 Heroku。一切似乎都运行良好,Rails 测试应用程序在我的本地服务器上运行,在推送到 Heroku 时我没有收到任何错误,但我一直收到“您要查找的页面不存在”。

我尝试添加根路由、安装“pg”gem、运行 rake db:migrate 等。此时我决定删除整个 Ruby 项目,重新开始并重新安装“pg”gem .

我的 Gemfile 看起来像这样: 来源' https://rubygems.org '

gem 'rails', '4.1.4'

group :production do
    gem 'pg'
end

group :development, :test do
    gem 'sqlite3'
end



gem 'sass-rails', '~> 4.0.3'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'

gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0',          group: :doc

gem 'spring',        group: :development

我的 Heroku 日志如下所示:

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.6.3
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Using json 1.8.1
       Using minitest 5.3.5
       Using thread_safe 0.3.4
       Using builder 3.2.2
       Using i18n 0.6.9
       Using erubis 2.7.0
       Using rake 10.3.2
       Using rack 1.5.2
       Using mime-types 1.25.1
       Using polyglot 0.3.5
       Using arel 5.0.1.20140414130214
       Using coffee-script-source 1.7.0
       Using execjs 2.2.1
       Using thor 0.19.1
       Using hike 1.2.3
       Using pg 0.17.1
       Using multi_json 1.10.1
       Using bundler 1.6.3
       Using tilt 1.4.1
       Using sass 3.2.19
       Using rdoc 4.1.1
       Using tzinfo 1.2.1
       Using treetop 1.4.15
       Using rack-test 0.6.2
       Using coffee-script 2.2.0
       Using uglifier 2.5.1
       Using sdoc 0.4.0
       Using activesupport 4.1.4
       Using mail 2.5.4
       Using actionview 4.1.4
       Using activemodel 4.1.4
       Using jbuilder 2.1.1
       Using actionpack 4.1.4
       Using railties 4.1.4
       Using actionmailer 4.1.4
       Using activerecord 4.1.4
       Using sprockets 2.11.0
       Using coffee-rails 4.0.1
       Using jquery-rails 3.1.1
       Using sprockets-rails 2.1.3
       Using turbolinks 2.2.2
       Using rails 4.1.4
       Using sass-rails 4.0.3
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Bundle completed (0.61s)
       Cleaning up the bundler cache.
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       Asset precompilation completed (2.01s)
       Cleaning assets
       Running: rake assets:clean
-----> WARNINGS:
       Include 'rails_12factor' gem to enable all platform features
       See https://devcenter.heroku.com/articles/rails-integration-gems for more information.

       You have not declared a Ruby version in your Gemfile.
       To set your Ruby version add this line to your Gemfile:
       ruby '2.0.0'
       # See https://devcenter.heroku.com/articles/ruby-versions for more information.

       No Procfile detected, using the default web server (webrick)
       https://devcenter.heroku.com/articles/ruby-default-web-server
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for Ruby  -> console, rake, web, worker

-----> Compressing... done, 21.2MB
-----> Launching... done, v7
       http://immense-lake-7186.herokuapp.com/ deployed to Heroku

任何帮助将不胜感激!谢谢!

最佳答案

错误

首先,出现 The Page You Were Looking For Doesn't Exist 的 Rails 错误是 Rails 错误,而不是 Heroku 错误:

enter image description here

不同之处在于,如果您遇到“Heroku”错误,那是平台级别的;这意味着它会在您的后端系统(数据库、依赖项、操作系统等)出现问题时显示:

enter image description here

--

由于您收到第一个 (red) 错误,您需要查看导致此错误的原因。

如果它发生在您第一次访问应用程序时,这可能意味着您没有声明root 路径或者您没有任何controller#actions 定义为处理请求。

我会试试这个:

#config/routes.rb
root to: "application#index"

#app/controllers/application_controller.rb
Class ApplicationController < ActionController::Base
    def index
    end
end

#app/views/application/index.html.erb
Test

当你再次推送到 Heroku 时,你应该尝试:

$ git add .
$ git commit -a -m "Heroku"
$ git push heroku master

关于ruby-on-rails - 无法找到 Rails/Heroku : "The page you were looking for doesn' t exist"的解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24591748/

相关文章:

ruby-on-rails - 在特定的 Rails 路由上触发 Rack 中间件

ruby-on-rails - 尝试访问时不引人注意地为关联创建记录?

ruby - 是否有易于在 Mac OS 上安装的 Ruby 跨平台 GUI?

ruby-on-rails - 生产中的 Rails Assets 出现问题

java - Unresolved 依赖 SBT play#sbt-plugin;2.0 : not found Play examples on Heroku

ruby-on-rails - 如何托管 Rails Web 应用程序

ruby-on-rails - 如何跳过brakeman扫描过程+Rails的具体方法

ruby-on-rails - 不确定在哪里(模型或 Controller )定义我的查找方法

ruby-on-rails - 在 Ruby on Rails 中将 YYYYDDMM_rest_of_filename.xls 更改为 YYYYMMDD_rest_of_filename.xls

ruby-on-rails - heroku rails 上的 Postgres 连接超时错误