0

我是使用 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.

当我转到 users/sign_up、users/sign_in 时会发生这种情况,但当我转到 users/edit 时不会发生这种情况

当我尝试访问 users/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

我很困惑下一步该做什么。任何帮助都非常感谢!

谢谢

4

2 回答 2

0

您需要定义一个根路径,以便 Rails 在某人打开根路径时知道将其发送到哪里。

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

一旦您登录,设计将希望重定向到某个地方,并且没有根路由,它无处可去。

root to: "statuses#index"可能是一个不错的起点

于 2013-10-11T15:56:36.233 回答
0

Rails 找不到你的root_url.

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

root to: '/'

root路由器的辅助方法在哪里to: 'controller#action'从您的一个控制器中获取选项哈希,例如users#index.

的值to可以采用字符串或其他 ruby​​ 对象,您将学习到!

查看本教程以获得更多想法 -> http://edgeguides.rubyonrails.org/routing.html

于 2013-10-11T15:56:54.590 回答