2011-03-25 145 views
1

我寫我的在軌第一應用,這裏是我做過什麼沒有路由匹配「/ admin」的錯誤

C:\Personal\rails\demo>ruby -v 
    ruby 1.9.2p136 (2010-12-25) [i386-mingw32] 

C:\Personal\rails\demo>rails -v 
    Rails 3.0.5 

C:\Personal\rails\demo>rails generate model book 
     invoke active_record 
     create db/migrate/20110325190010_create_books.rb 
     create app/models/book.rb 
     invoke test_unit 
     create  test/unit/book_test.rb 
     create  test/fixtures/books.yml 

C:\Personal\rails\demo>rake db:migrate 
(in C:/Personal/rails/demo) 
== CreateBooks: migrating ==================================================== 
-- create_table(:books) 
    -> 0.0000s 
== CreateBooks: migrated (0.0000s) =========================================== 


C:\Personal\rails\demo>rails generate controller admin 
     create app/controllers/admin_controller.rb 
     invoke erb 
     create app/views/admin 
     invoke test_unit 
     create test/functional/admin_controller_test.rb 
     invoke helper 
     create app/helpers/admin_helper.rb 
     invoke test_unit 
     create  test/unit/helpers/admin_helper_test.rb 

然後我編輯的admin_controller.rb如下:

class AdminController < ApplicationController 
    scaffold :book 
end 

這裏是的routes.rb文件

Demo::Application.routes.draw do 
    # The priority is based upon order of creation: 
    # first created -> highest priority. 

    # Sample of regular route: 
    # match 'products/:id' => 'catalog#view' 
    # Keep in mind you can assign values other than :controller and :action 

    # Sample of named route: 
    # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase 
    # This route can be invoked with purchase_url(:id => product.id) 

    # Sample resource route (maps HTTP verbs to controller actions automatically): 
    # resources :products 

    # Sample resource route with options: 
    # resources :products do 
    #  member do 
    #  get 'short' 
    #  post 'toggle' 
    #  end 
    # 
    #  collection do 
    #  get 'sold' 
    #  end 
    # end 

    # Sample resource route with sub-resources: 
    # resources :products do 
    #  resources :comments, :sales 
    #  resource :seller 
    # end 

    # Sample resource route with more complex sub-resources 
    # resources :products do 
    #  resources :comments 
    #  resources :sales do 
    #  get 'recent', :on => :collection 
    #  end 
    # end 

    # Sample resource route within a namespace: 
    # namespace :admin do 
    #  # Directs /admin/products/* to Admin::ProductsController 
    #  # (app/controllers/admin/products_controller.rb) 
    #  resources :products 
    # end 

    # You can have the root of your site routed with "root" 
    # just remember to delete public/index.html. 
    # root :to => "welcome#index" 

    # See how all your routes lay out with "rake routes" 

    # This is a legacy wild controller route that's not recommended for RESTful applications. 
    # Note: This route will make all actions in every controller accessible via GET requests. 
    # match ':controller(/:action(/:id(.:format)))' 
end 

然而,當我去http://localhost:3000/admin,我得到一個「無路由匹配」/ADMI ñ「」錯誤。我注意到我的routes.rb只有註釋行。我做錯什麼了嗎?

+0

您可以發佈您的routes.rb文件? – huntsfromshadow 2011-03-25 20:10:14

+0

感謝您的期待。我已經將routes.rb文件的內容添加到問題中。 – oogle 2011-03-25 20:53:49

回答

1

您沒有添加管理員的路線,爲什麼所有的路由註釋掉。

如果管理員是資源加入這一行

resources :admin 

另外,在你的控制器,你將需要一個指數法和索引視圖文件,因爲http://localhost:3000/admin會帶你去

+0

我按照「使用Rails進行敏捷Web開發」一書中的說明,讓我試試 – oogle 2011-03-25 21:22:01

+0

嗯,給了我一個錯誤「未定義的方法'腳手架'的AdminController:類」上面提到的書是用於導軌2,看起來像在那裏的步驟不再持有3.0 – oogle 2011-03-25 21:27:08

+0

刪除該線腳手架:書 – Shiv 2011-03-25 21:29:03

0

嘗試從該行刪除註釋:

match ':controller(/:action(/:id(.:format)))' 
+1

沒有,但沒有工作:-( – oogle 2011-03-25 21:19:27

相關問題