2011-07-28 62 views
0

尋找一點幫助理解這條路線如何工作?Rails 3:這條路線是做什麼的?

新航線:

resources :artists do 
    resources :users 
end 

整個路線

resources :artists do 
    resources :users 
    end 

    match 'auth/:provider/callback' => 'authentications#create' 
    resources :authentications 

    devise_for :admins 
    match '/admin' => 'RailsAdmin/Main#index' 

    devise_for :users, :controllers => {:registrations => 'registrations'} do 
    match '/users/change_password', :to => 'registrations#change_password' 
    match '/users/edit_account', :to => 'registrations#edit_account' 
    end 


    resources :posts do 
     member do 
     get :likers 
     end 
     collection do 
     get :search 
     end 
    end 

    resources :relationships, :only => [:create, :destroy] 
    resources :appreciations, :only => [:create, :destroy] 

    match '/a_json/:id', :to => 'artists#index' 
    match '/s_json/:id', :to => 'stores#index' 

    match '/contact', :to => 'pages#contact' 
    match '/about', :to => 'pages#about' 
    match '/help', :to => 'pages#help' 
    match '/blog', :to => 'pages#blog' 


    resources :users do 
    member do 
    get :following, :followers, :likes 
    end 
end 

    # This is a legacy wild controller route that's not recommended for RESTful applications. 
    # Note: This route will make all actions in every controller accessible via GET requests. 
    # match ':controller(/:action(/:id(.:format)))' 
    match '/:id' => 'users#show', :constraints => {:id => /[^\/]+/}, :as => :global_user 
    root :to => "pages#home" 
end 

回答

1

這將創建嵌套的路線,讓您使用的URL像/artists/5/users/45,這將調用UsersController#顯示與參數artist_id這是5 ,以及一個參數爲id,它的值爲45.所有其他通常的RESTful路由也是在單個藝術家下創建的「嵌套」。

Rails實際上有一個工具,用於向您顯示已生成的路由:只需運行rake routes即可查看。