【问题标题】:Rails 3 Route Get No Route matchesRails 3 Route 获取无路线匹配
【发布时间】:2012-03-07 17:57:27
【问题描述】:

我在 Rails 3.0.9 下。

我有路线:

get 'account/index'

控制台上有这样的信息:

account_index GET    /account/index(.:format)   {:controller=>"account", :action=>"index"}

但是当我尝试 http://127.0.0.1:3000/account/ 时,
我得到 No route matches "/account"

提前致谢。

【问题讨论】:

    标签: ruby-on-rails-3 routing


    【解决方案1】:

    请参阅Routes explanation 以获得更详细的说明。此外,以下行 (match :to =>) 应位于您的 routes.rb 文件顶部 match ':controller(/:action(/:id))(.:format)' 之前。希望这会有所帮助。

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

    【讨论】:

      【解决方案2】:

      是的,因为路由是 /account/index 而不是 /account 试试get 'account#index'。

      【讨论】:

      • 谢谢蒂姆。但是当我尝试 get 'account#index' 我得到 missing :controller 错误。但是使用 match 'account' => 'account#index', :via => :get 解决了我的问题。但这不是我需要的。
      【解决方案3】:

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

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

      完成此操作后,您必须使用 http://127.0.0.1:3000/account/index 访问您的页面

      【讨论】:

      • Sonu,非常感谢您的建议。但它不适合我,因为我想参考 127.0.0.1:3000/account 而不是 127.0.0.1:3000/account/index
      • @LeshaPipeev,在您的 routes.rb 文件中输入之前的建议后,您可以尝试以下操作吗? ``匹配'/account',:to =>'account#index'`
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-14
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多