Rails 3:这条路线做什么?

时间:2011-07-28 22:57:36

标签: ruby-on-rails-3 routes

寻找一点帮助,了解这条路线的运作方式?

新路线:

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 个答案:

答案 0 :(得分:1)

这将创建嵌套路由,允许您使用/artists/5/users/45之类的URL,它将调用UsersController#show,参数artist_id为5,参数id为45所有其他常用的RESTful路由也是在一个艺术家的“嵌套”下创建的。

Rails实际上有一个工具可以显示生成的路线:只需运行rake routes即可查看。