Rails路由问题。将资源从复数更改为单数给出“无路由匹配”错误

时间:2011-04-24 15:48:20

标签: ruby-on-rails-3 rest routing routes

**更新:这个问题是关于Rails中的一个错误:**

https://rails.lighthouseapp.com/projects/8994/tickets/267

**结束更新。 **

我尝试使用单一资源(根据here)因为我喜欢更好的类型网址

/user/new

相比
/users/new

所以在我的routes.rb中我改变了

resources :users

resources :user, :controller => 'users'

现在在我看来命令

form_for(@user) do |f|

给出错误:

No route matches {:controller=>"users"}

有任何线索吗?

这是佣金路线的输出

user_index GET    /user(.:format)          {:action=>"index",  :controller=>"users"}
           POST   /user(.:format)          {:action=>"create", :controller=>"users"}
  new_user GET    /user/new(.:format)      {:action=>"new",    :controller=>"users"}
 edit_user GET    /user/:id/edit(.:format) {:action=>"edit",   :controller=>"users"}
      user GET    /user/:id(.:format)      {:action=>"show",   :controller=>"users"}
           PUT    /user/:id(.:format)      {:action=>"update", :controller=>"users"}
           DELETE /user/:id(.:format)      {:action=>"destroy",:controller=>"users"}

2 个答案:

答案 0 :(得分:3)

请尝试resource :user而不是resources :user,因为这是一条单一的路线 一条独特的资源丰富的路线会产生这些帮助:

  • new_user_path返回/ user / new
  • edit_user_path返回/ user / edit
  • user_path返回/ user

因此,users_path现在为user_path

答案 1 :(得分:2)

这个问题是关于Rails中的一个错误:

https://rails.lighthouseapp.com/projects/8994/tickets/267