欢迎光临Software MyZone,有问题可留言或到站点论坛发帖,争取第一时间帮忙解决 || 站点论坛:火龙论坛 || 淘宝小店:应小心的易淘屋 【欢迎大家提建设性意见】

rails路由–self

一:命名空间下的resources与member、collection
get ‘columns/:column_id/content/:content_id’ =>”columns#content”,:as=>”column_content”
get ‘columns/:column_id/content/:content_id/comments’ =>”comments#index”,:as=>”comments_index”
post ‘columns/:column_id/content/:content_id/comment’ =>”comments#create”,:as=>”comment_create”(#-1)
match’users/edit’#(0)
namespace :user do
resources :users do #(1)
get ‘editpwd’, :o n => :member #(2)

member do #(3)
get ‘mem_edit1′
get ‘mem_edit2′
end

collection do #(4)
get ‘col_edit1′
get ‘col_edit2′
end
match ‘myeditmath’ #(5)
get ‘myeditget’ #(6)
end
end
解析:
-1 多个参数也可以自己定制路由,写helper
0: users_edit /users/edit(.:format) {:action => ‘edit’, :contorller => ‘users’}
生成两套路由:resources :user do … end –resources:生成基本的路由 里面的:生成嵌套路由
1:resource 默认路由
user_users get /user/users(.:format) {:action=>’index’,:controller => ‘user/users/}
user_users post /user/users(.:format) {:action => ‘create’, :controller => ‘user/users’}

user_user get /user/user/:id(.:format){:action=>’show’,:controller=>’user/users’}
user_user put /user/user/:id(.:format){:action=>’update’,:controller=>’user/users’}
user_user delete /user/user/:id(.:format){:action=>’destroy’,:controller=>’user/users’}

new_user_user get /user/users/new(.format){:action=>’new’,:controller=>’user/users’}
edit_user_user get /user/users/:id/edit(.:format) {:action=>’edit’,:controller=> ‘user/users’}

2:editpwd_user_user get /user/users/:id/editpwd(.:format) {:action => ‘editpwd’, :controller => ‘user/users’}

3:mem_edit1_user_user get /user/users/:id/mem_edit1(.:format) {:action => ‘mem_edit1′, :controller => ‘user/users’}
mem_edit2_user_user get /user/users/:id/mem_edit2(.:format) {:action => ‘mem_edit2′, :controller => ‘user/users’}
4:col_edit1_user_users get /user/users/col_edit1(.:format) {:action => ‘col_edit1′, :controller => ‘user/users’}
col_edit2_user_users get /user/users/col_edit2(.:format) {:action => ‘col_edit1′, :controller => ‘user/users’}

5: user_myeditmacth /user/users/:course_id/myeditmatch(.:format) {:action => ‘myeditmathc’, :controller => ‘user/users’}

6: user_myedit get /user/users/:course_i/myeditget(.:format){:action => ‘myeditget’, :controller =>’user/users’ }
二:待定匹配
1.match “/site/show_product/:id.:format” => “site#show_product#id”
2.get ‘atricles/:atricle_id/comment/:comment_id’ =>”articles#comment”,:as=>”articles_comment”
三:注意:member,collection在资源内使用 二/2在资源外使用

详细参考:http://firedragonpzy.iteye.com/admin/blogs/1384256