没有路由匹配[GET]“/”设计用户Sign_Up

时间:2013-10-11 15:50:38

标签: ruby-on-rails ruby devise

我是使用Rails的新手。我正在关注Treehouse“构建一个简单的Ruby on Rails应用程序”教程。直到现在,一切都很顺利。

我正在尝试生成设计视图但是当我转到localhost:3000 / users / sign_up时出现错误

Routing Error

No route matches [GET] "/"
Try running rake routes for more information on available routes.

当我转到用户/ sign_up,users / sign_in而不是去用户/编辑时会发生这种情况

当我尝试去用户/ sign_up时,终端向我吐口水

    Started GET "/users/sign_up" for 127.0.0.1 at 2013-10-11 11:16:24 -0400
Processing by Devise::RegistrationsController#new as HTML
User Load (0.1ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 48ms (ActiveRecord: 1.7ms)


Started GET "/" for 127.0.0.1 at 2013-10-11 11:16:24 -0400

ActionController::RoutingError (No route matches [GET] "/"):
actionpack (3.2.12) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.12) lib/rails/rack/logger.rb:32:in `call_app'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `block in call'
activesupport (3.2.12) lib/active_support/tagged_logging.rb:22:in `tagged'
railties (3.2.12) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.5) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.5) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.12) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.5) lib/rack/lock.rb:15:in `call'
actionpack (3.2.12) lib/action_dispatch/middleware/static.rb:62:in `call'
railties (3.2.12) lib/rails/engine.rb:479:in `call'
railties (3.2.12) lib/rails/application.rb:223:in `call'
rack (1.4.5) lib/rack/content_length.rb:14:in `call'
railties (3.2.12) lib/rails/rack/log_tailer.rb:17:in `call'
rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'


Rendered /usr/local/rvm/gems/ruby-1.9.3-p392/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.6ms)
^C[2013-10-11 11:19:28] INFO  going to shutdown ...
[2013-10-11 11:19:28] INFO  WEBrick::HTTPServer#start done.
Exiting## Heading ##

当我运行rake路线时,这就是它的样子

    Mikes-MacBook-Pro:treebook mike$ rake routes
    new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
        user_session POST   /users/sign_in(.:format)       devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
       user_password POST   /users/password(.:format)      devise/passwords#create
   new_user_password GET    /users/password/new(.:format)  devise/passwords#new
  edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                     PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)          devise/registrations#cancel
   user_registration POST   /users(.:format)               devise/registrations#create
new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                     PUT    /users(.:format)               devise/registrations#update
                     DELETE /users(.:format)               devise/registrations#destroy
            statuses GET    /statuses(.:format)            statuses#index
                     POST   /statuses(.:format)            statuses#create
          new_status GET    /statuses/new(.:format)        statuses#new
         edit_status GET    /statuses/:id/edit(.:format)   statuses#edit
              status GET    /statuses/:id(.:format)        statuses#show
                     PUT    /statuses/:id(.:format)        statuses#update
                     DELETE /statuses/:id(.:format)        statuses#destroy

我很难过接下来要做什么。任何帮助都非常感激!

由于

2 个答案:

答案 0 :(得分:0)

您需要定义根路由,以便Rails知道在打开根路径时将某人发送到何处。

http://guides.rubyonrails.org/routing.html#using-root

一旦你登录,Devise就会想要重定向某个地方,没有根路线,它无处可去。

root to: "statuses#index"可能是一个开始的好地方

答案 1 :(得分:0)

Rails无法找到您的root_url

尝试将以下内容添加到routes.rb并重新启动服务器。

root to: '/'

其中root是路由器的辅助方法,从您的某个控制器获取选项hash to: 'controller#action',例如users#index

to的值可以包含字符串或其他红宝石对象,您将学习它们!

查看本教程以获取更多创意 - > http://edgeguides.rubyonrails.org/routing.html