简体   繁体   English

收到路由错误(路由不匹配)

[英]Getting Routing Error(Route doesn't match)

I am trying to update multi-select list on change but I am getting a routing error. 我正在尝试更新更改时的多选列表,但出现路由错误。 I call this with an onchange event $.post("/levels/category_lists_for_level" 我用onchange事件$.post("/levels/category_lists_for_level"

I have an action called category_lists_for_level in a controller called level . 我在名为level的控制器中有一个名为category_lists_for_level的动作。

My routes file looks like this. 我的路线文件如下所示。

match '/levels/category_lists_for_level/:id'  => 'levels#category_lists_for_level'
resources :levels 
resources :levels , :collection => {:category_lists_for_level => :get}

What am I doing wrong here? 我在这里做错了什么? I never had any problem in Rails 2, all I used to add the collection. 我从未在Rails 2中遇到任何问题,所有我用来添加集合的东西。

It is a bit hard to say exactly what you need since as others have said you are missing some info, but you have a few apparent things going on here: 确切地说您需要什么有点困难,因为正如其他人所说的那样,您缺少一些信息,但是这里有一些明显的事情要发生:

  1. You are duplicating routes 您正在复制路线
  2. You have the route set on a collection and a member 您在集合和成员上设置了路线
  3. You are allowing multiple requests types (get and post) to access this route. 您允许多种请求类型(获取和发布)访问此路由。

If you would like to have this operate on a collection you just need: 如果您希望对集合执行此操作,则只需要:

resources :levels do
  post "category_lists_for_level", :on => :collection 
end 

or on a member: 或成员上:

resources :level do 
  get "category_lists_for_level", :on => :member
end

This will reduce your routes. 这将减少您的路线。 Just use rake routes | grep level 只需使用rake routes | grep level rake routes | grep level to get the routes for this controller. rake routes | grep level以获取此控制器的路由。

Take a look at this for some more info. 看看这个以获得更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM