首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

beast学习札记——1,routs.rb

2012-12-19 
beast学习笔记——1,routs.rb(原稿)beast学习笔记——1,routs.rb参考http://www.iteye.com/topic/78885、http:/

beast学习笔记——1,routs.rb

(原稿)beast学习笔记——1,routs.rb

参考http://www.iteye.com/topic/78885、http://hi.baidu.com/haifreeidea/blog/item/c1a830ef2a92ee212cf534f0.html/cmtid/fd826e81a913b9d99023d95c?1,(1)代码map.root :controller => 'forums', :action => 'index'(2)表示首页的转向(3)其他REST与非REST的routs不同【1】REST通过ruby script/generate scaffold_resource project name:string desc:text的方式来生成MVC,routs.rb中会发现:route map.resources :projects?【2】非REST则会看见默认内容:map.connect ':controller/service.wsdl',:action=>'wsdl'map.connect ':controller/:action/:id'?2,(1)代码
??map.activate '/activate/:activation_code', :controller => 'users', ???:action => 'activate', :activation_code => nil
??map.signup ??'/signup', ???????????????????:controller => 'users', ???:action => 'new'
??map.login ???'/login', ????????????????????:controller => 'sessions', :action => 'new'
??map.logout ??'/logout', ???????????????????:controller => 'sessions', :action => 'destroy'?(2)表示:map.signup ??'signup', ???????:controller => 'users', ??:action => 'new' ----表示:当调用 signup 时,会调用相应的controller和action?3,(1)代码??map.resources :forums, :has_many => :posts do |forum|
????forum.resources :topics do |topic|
??????topic.resources :posts
??????topic.resource :monitorship
????end
????forum.resources :posts
??end
??
??map.resources :posts, :collection => {:search => :get}
??map.resources :users, :member => { :suspend ??=> :put,
?????????????????????????????????????:settings ?=> :get,
?????????????????????????????????????:make_admin => :put,
?????????????????????????????????????:unsuspend => :put,
?????????????????????????????????????:purge ????=> :delete },
????????????????????????:has_many => [:posts]?(2)表示【1】map.resources :posts, :collection => {:search => :get}--表示路由规则 /posts;search,使用get来访问。【2】 map.resources :users, :member => { :suspend ??=> :put,
?????????????????????????????????????:settings ?=> :get,
?????????????????????????????????????:make_admin => :put,
?????????????????????????????????????:unsuspend => :put,
?????????????????????????????????????:purge ????=> :delete },
????????????????????????:has_many => [:posts]--表示路由规则 /users/1;suspend,/users/1;settings等等【3】do |forum|与do |topic|的两次嵌套循环--表示路由规则/forums/1/topics/1/posts/1,forums/1/topics/1/monitorship/1?4,(1)代码??map.with_options :controller => 'posts', :action => 'monitored' do |map|
????map.formatted_monitored_posts 'users/:user_id/monitored.:format'
????map.monitored_posts ??????????'users/:user_id/monitored'
??end(2)表示等同于代码:map.formatted_monitored_posts ?'users/:user_id/monitored.:format',:controller => 'posts', :action => 'monitored'map.monitored_posts ?????????????????'users/:user_id/monitored', :controller => 'posts', :action => 'monitored' ?不错的总结

热点排行