将路由更改为索引路径

时间:2014-04-15 20:19:54

标签: ruby-on-rails

我有/users/1/settings/profile/1/settings。如何修改路由以使其更简单,例如/settings

routes.rb中:

 get 'signup' => 'users#new'
  get 'login' => 'sessions#new'
  get 'logout' => 'sessions#destroy'
  get 'edit' => 'users#edit'
  get "/profile/:id" => "users#show"
  get "profile/:id/settings" => 'users#edit'
  get 'settings/:id' => 'users#settings'

  resources :users do  
    get 'settings', on: :member  
    post 'follow', on: :member 
    post 'unfollow', on: :member
    get "follow", on: :member 
  end
   end

1 个答案:

答案 0 :(得分:0)

根据railscasts

  resourses: users, :has_many => :settings, :shallow => true 

会帮助你

6:30

观看this