我在Rails 3.0.9下。
Rails 3路線獲取無路線匹配
我的路線:
get 'account/index'
有這樣的信息,在控制檯:
account_index GET /account/index(.:format) {:controller=>"account", :action=>"index"}
但是當我嘗試http://127.0.0.1:3000/account/,
我得到沒有路線匹配「/ account」
在此先感謝。
我在Rails 3.0.9下。
Rails 3路線獲取無路線匹配
我的路線:
get 'account/index'
有這樣的信息,在控制檯:
account_index GET /account/index(.:format) {:controller=>"account", :action=>"index"}
但是當我嘗試http://127.0.0.1:3000/account/,
我得到沒有路線匹配「/ account」
在此先感謝。
請訪問您的網頁是指Routes explanation了更詳細的解釋。此外,在match ':controller(/:action(/:id))(.:format)'
之前,以下行(match:to =>)應位於routes.rb文件的頂部。希望這可以幫助。
match '/account', :to => 'account#index'
是的,因爲路線是/帳戶/索引而不是/帳戶 嘗試get 'account#index'
。
謝謝Tim。但是,當我嘗試**獲得'帳戶#索引'**我得到**失蹤:控制器**錯誤。但是使用** match'account'=>'account#index',:via =>:get **解決了我的問題。但它不是我所需要的。 – 2012-03-08 10:58:55
@Lesha,我對Rails也相對陌生。以下將是您的路線文件中更通用的方式,而不是get'controller#action'。
match ':controller(/:action(/:id))(.:format)'
此過程完成後,你將不得不使用http://127.0.0.1:3000/account/index
Sonu,非常感謝您的建議。但它不適合我,因爲我想參考* http://127.0.0.1:3000/account * not * http://127.0.0.1:3000/account/index * – 2012-03-08 10:54:13
@LeshaPipiev,你可以試試以下在您的routes.rb文件中放入之前的建議之後? ''match'/ account',:to =>'account#index'' – Prashanth 2012-03-08 11:22:01
非常感謝,Sonu。現在對我來說很清楚。 – 2012-03-08 12:13:26
太棒了,我很高興它爲你工作... – Prashanth 2012-03-08 15:20:21