2012-03-07 80 views
0

我在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”

在此先感谢。

回答

1

请访问您的网页是指Routes explanation了更详细的解释。此外,在match ':controller(/:action(/:id))(.:format)'之前,以下行(match:to =>)应位于routes.rb文件的顶部。希望这可以帮助。

match '/account', :to => 'account#index' 
+0

非常感谢,Sonu。现在对我来说很清楚。 – 2012-03-08 12:13:26

+0

太棒了,我很高兴它为你工作... – Prashanth 2012-03-08 15:20:21

0

是的,因为路线是/帐户/索引而不是/帐户 尝试get 'account#index'

+0

谢谢Tim。但是,当我尝试**获得'帐户#索引'**我得到**失踪:控制器**错误。但是使用** match'account'=>'account#index',:via =>:get **解决了我的问题。但它不是我所需要的。 – 2012-03-08 10:58:55

0

@Lesha,我对Rails也相对陌生。以下将是您的路线文件中更通用的方式,而不是get'controller#action'。

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

此过程完成后,你将不得不使用http://127.0.0.1:3000/account/index

+0

Sonu,非常感谢您的建议。但它不适合我,因为我想参考* http://127.0.0.1:3000/account * not * http://127.0.0.1:3000/account/index * – 2012-03-08 10:54:13

+0

@LeshaPipiev,你可以试试以下在您的routes.rb文件中放入之前的建议之后? ''match'/ account',:to =>'account#index'' – Prashanth 2012-03-08 11:22:01