2013-10-11 117 views
0

我是全新的Rails工作。我正在關注Treehouse「構建簡單的Ruby on Rails應用程序」教程。直到現在,一切都很順利。沒有路由匹配[GET]「/」設計用戶Sign_Up

我想生成設計的看法,但是當我去到本地主機:3000 /用戶/ sign_up我得到一個錯誤說

Routing Error 

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

發生這種情況時,我去給用戶/ sign_up,用戶/ sign_in但是當我去不給用戶/編輯

當我嘗試去用戶/ sign_up這是終端我

Started GET "https://stackoverflow.com/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 ## 

吐回當我運行耙路線,這是什麼樣子

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 

我很害怕接下來該做什麼。任何幫助超級讚賞!

感謝

回答

0

你需要這樣的Rails知道在哪裏可以派人當他們剛剛打開的根路徑定義根路徑。

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

設計將要重定向一旦某處您登錄,沒有根的路線,它無處可去。

root to: "statuses#index"可能是一個良好的開端

+0

非常感謝,完全工作!但是現在我在訪問本地主機時遇到同樣的問題:3000/users/sign_out 這就是終端的樣子: 2013-10-11 12.0.0.1開始GET「/ users/sign_out」 :11:21 -0400 ActionController :: RoutingError(沒有路由匹配[GET]「/ users/sign_out」): –

+0

它看起來像/ users/sign_out只採用DELETE HTTP方法。您很可能需要創建專門鏈接來點擊,而不是直接訪問該路徑。就像'<%= link_to('Logout',destroy_user_session_path,:method =>:delete)%>'應該這樣做。 –

+0

此外,這裏有一個完整的指南,將所有設計相關的鏈接添加到所有頁面上顯示的菜單中:https://github.com/plataformatec/devise/wiki/How-To:-Add-sign_in,- sign_out,-and-sign_up-links-your-layout-template –

0

的Rails找不到你root_url

嘗試將以下內容添加到您的routes.rb並重新啓動服務器。

root to: '/'

哪裏root是你的路由器從控制器之一,如​​拍攝選項哈希to: 'controller#action'一個輔助方法。

to的值可以帶字符串或其他紅寶石對象,您將學習!

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

相關問題