trying_hal9000
trying_hal9000

Reputation: 4403

Rails 3: What does this route do?

Looking for a little helping understanding how this route would work?

New route:

resources :artists do
  resources :users
end

entire routes

 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

Upvotes: 0

Views: 291

Answers (1)

Jeremy Roman
Jeremy Roman

Reputation: 16355

This would create nested routes, allowing you to use URLs like /artists/5/users/45, which would call UsersController#show with a parameter artist_id which was 5, and a parameter id which was 45. All of the other usual RESTful routes are also created "nested" under a single artist.

Rails actually has a tool for showing you what routes have been generated: just run rake routes to take a peek.

Upvotes: 1

Related Questions