我正在关注本教程,但是当我部署到heroku并使用命令heroku open
时,我得到“您正在查找的页面不存在。 “我一直在阅读,似乎每个人的问题都没有设置根路线。我将这行添加到我的config/routes.rb文件的开始部分:Heroku - 找不到页面 - 我想我已经设置了根路由
root 'users#index'
但现在可用。我承诺了,推到了heroku,并且也在之后迁移了db。有任何想法吗?
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
# GET /users
# GET /users.json
def index
@users = User.all
end
# GET /users/1
# GET /users/1.json
def show
end
# GET /users/new
def new
@user = User.new
end
# GET /users/1/edit
def edit
end
# POST /users
# POST /users.json
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render action: 'show', status: :created, location: @user }
else
format.html { render action: 'new' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
respond_to do |format|
if @user.update(user_params)
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
# DELETE /users/1
# DELETE /users/1.json
def destroy
@user.destroy
respond_to do |format|
format.html { redirect_to users_url }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:name, :email)
end
end
也许我没有正确创建它们?大写字母还是什么?
这里是我的routes.rb:
DemoApp::Application.routes.draw do
root 'users#index'
resources :microposts
resources :users
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
这里是我的Heroku的日志:
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:680:in `call'
2014-02-07T08:00:40.454530+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
2014-02-07T08:00:40.454530+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:59:in `call'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:59:in `each'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:71:in `block in call'
2014-02-07T08:00:40.454530+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:66:in `controller'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2014-02-07T08:00:40.454530+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:44:in `call'
2014-02-07T08:00:40.454530+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/flash.rb:241:in `call'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/cookies.rb:486:in `call'
2014-02-07T08:00:40.454762+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/query_cache.rb:36:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:373:in `_run__3113425911459750945__call__callbacks'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/rub
y/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `tagged'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `block in call'
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/static.rb:64:in `call'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `call'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-02-07T08:00:40.456085+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `each'
2014-02-07T08:00:40.456085+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2014-02-07T08:00:40.456085+00:00 app[web.1]: ActionController::RoutingError (uninitialized constant UsersController):
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:97:in `call'
2014-02-07T08:00:40.456085+00:00 app[web.1]:
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/e
ngine.rb:511:in `call'
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:76:in `controller_reference'
2014-02-07T08:00:40.456085+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `inject'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:44:in `call'
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2014-02-07T08:00:40.456085+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:224:in `constantize'
2014-02-07T08:00:40.456085+00:00 app[web.1]:
2014-02-07T08:00:40.456085+00:00 app[web.1]:
2014-02-07T08:00:40.455714+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/flash.rb:241:in `call'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:59:in `each'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:71:in `block in call'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/conditionalget.rb:25:in `call'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:66:in `controller'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/etag.rb:23:in `call'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/cookies.rb:486:in `call'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:80:in `run_callbacks'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/callbacks.rb:373:in `_run__3113425911459750945__call__callbacks'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:225:in `context'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:626:in `call'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activerecord-4.0.2/lib/active_record/query_cache.rb:36:in `call'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `block in tagged'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:25:in `tagged'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `block in call'
2014-02-07T08:00:40.456655+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/static.rb:64:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
2014-02-07T08:00:40.454935+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/session/abstract/id.rb:220:in `call'
2014-02-07T08:00:40.458180+00:00 app[web.1]:
2014-02-
07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2014-02-07T08:00:40.458180+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-02-07T08:00:40.458180+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2014-02-07T08:00:40.458180+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:38:in `call_app'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `block in tagged'
2014-02-07T08:00:40.455521+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:25:in `tagged'
2014-02-07T08:00:40.456085+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `const_get'
2014-02-07T08:00:40.456085+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/inflector/methods.rb:226:in `block in constantize'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/journey/router.rb:59:in `call'
2014-02-07T08:00:40.456270+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/routing/route_set.rb:680:in `call'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:38:in `call_app'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.2/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/rack/logger.rb:20:in `call'
2014-02-07T08:00:40.456850+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.2/lib/active_support/tagged_logging.rb:67:in `tagged'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/application.rb:97:in `call'
2014-02-07T08:00:40.457227+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.2/lib/rails/engine.rb:511:in `call'
2014-02-07T08:00:40.458180+00:00 app[web.1]:
2014-02-07T08:00:40.458180+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
嗯...所以不是那么...... –
我知道这是一个很大的代码,但你能发表您的routes.rb?您可以删除控制器,因为这没有用。我假设粘贴的控制器代码中只有一个'''end'',它在实际代码中存在。 –
是的,我觉得我清除了所有正常的错误。但是为什么我仍然得到ActionController :: RoutingError(未初始化的常量UsersController):在日志中 – mharris7190