为什么这条路线代码不会呈现用户索引页面?

时间:2016-10-19 16:21:06

标签: ruby-on-rails

我已经完成了Hartl教程并设法在friendly_id的帮助下添加一些虚荣URL并配置路由文件。他们使用/ username而不是/ users / id

我通过安装friendly_id并使用以下命令配置routes.rb来完成此操作:

  get '/users',      to: 'users#index'
  resources :users, path: '' do
    member do
      get :following, :followers
    end
  end

但是,我想让代码变得更漂亮,所以我试着将其更改为:

  resources :users, except: :index, path: '' do
  member do
      get :following, :followers
    end
  end

但它没有呈现/ users索引页面!我写错了这个代码还是我疯了?

编辑:

忘记添加,还有另一个资源:用户进一步向下。这是我的整个routes.rb:

Rails.application.routes.draw do


  get 'password_resets/new'

  get 'password_resets/edit'

  root 'static_pages#home'
  get '/help',       to: 'static_pages#help'
  get '/about',      to: 'static_pages#about'
  get '/contact',    to: 'static_pages#contact'
  get '/signup',     to: 'users#new'
  post '/signup',    to: 'users#create'
  get '/login',      to: 'sessions#new'
  post '/login',     to: 'sessions#create'
  delete '/logout',  to: 'sessions#destroy'
  get '/users',      to: 'users#index'
  resources :users, path: '' do
    member do
      get :following, :followers
    end
  end

  resources :users
  resources :account_activations, only: [:edit]
  resources :password_resets,     only: [:new, :create, :edit, :update]
  resources :microposts,          only: [:create, :destroy]
  resources :relationships,       only: [:create, :destroy]
end

2 个答案:

答案 0 :(得分:1)

except:语句排除索引的路由。实际上,为索引操作生成用户except的资源路由。

尝试:

 resources :users, path: '' do
  member do
      get :following, :followers
    end
  end

答案 1 :(得分:1)

您已移除index并将其从资源中排除。