学习ROR,遭遇“Routing Error”了,请指点

TheRuby 2010-07-31 01:36:34
  这段时间看《Web开发敏捷之道——应用Rails进行敏捷Web开发(第3版)》学习ror,版本跟书上的一样,rubu是1.8.6,rails是2.2.2。
  自己做其他ror应用的时候,controller和action都有了(depot没这个问题),但是浏览器里面老是提示如下:


Routing Error

No route matches "/xxx/yyy" with {:method=>:get}


我的routes.rb如下:


ActionController::Routing::Routes.draw do |map|

map.resources :products

map.resources :products

map.resources :products

map.connect ':controller/:action/:id';
map.connect ':controller/:action/:id.:format';
end


google后有一个说法让加上:

map.resources :Xxx, :collection => { :yyy => :get };


之后确实能行了

请问:
1、因之前按第2版做同样的应用的时候没出现过这问题,routing error是rails 2.0新增加了规则所致吗?

2、按上述那个语句,在{ }里要每个action写一次,有什么通配符之类的方式吗

3、我的url明明符合map.connect的规则,为什么老是routing error?map.resource和map.connect之间是否有什么特别的规则需要协调的呢?


请指点,谢谢
...全文
344 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
TheRuby 2010-08-03
  • 打赏
  • 举报
回复
谢谢,结贴
saint1126 2010-07-31
  • 打赏
  • 举报
回复
map.resources :xxx, :collection => { :yyy => :get };

说明你使用的restful路由,应该是使用scaffold的生成的吧,rails支持了REST路由,如果你的routes.rb中包含了 map.resources :products
相当于默认支持了
map.resources :products,:collection => { :index => :get,:new=>:get,:create:=>:post},:member=>{:edit=>:get,:update=>:put,:destory=>:delete,:show=>:get}

如果想支持xxx/yyy需要在在collection中添加,:collection => { :yyy => :get };


如果你想和之前一样不需要restful的路由的话,只需要注释掉

map.resources :xxx

xxx代表什么,你懂得吧,看你的路由写了3个


map.resources :products

map.resources :products

map.resources :products


我想你应该是products后面添加自己的方法吧.

希望你看下这篇文章.http://guides.rubyonrails.org/routing.html
大家一起学习,你遇到的问题,也是我当初遇到的问题.

xmx2009 2010-07-31
  • 打赏
  • 举报
回复
帮顶,学习

2,763

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ruby/Rails
社区管理员
  • Ruby/Rails社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧