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

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

参考
 
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'  

你可能感兴趣的:(html,mvc,Blog,REST,Ruby)