3

我的 routes.db 文件中有这段代码:

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

我得到了错误:

can't use member outside resource(s) scope (ArgumentError) 

我该如何解决?

更新:这是我的 routes.db 文件的所有代码:

SampleApp::Application.routes.draw do
get "sessions/new"

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

resources :sessions, :only => [:new, :create, :destroy]
resources :microposts, :only => [:create, :destroy]
resources :relationships, :only => [:create, :destroy]

match '/signup', :to => 'users#new' 
match '/signin',  :to => 'sessions#new'
match '/signout', :to => 'sessions#destroy' 

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

root :to => 'pages#home'
4

1 回答 1

7

在您的代码中,您具有以下内容:

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

这意味着您缺少资源声明的 do 语句和 end 语句,请将其更改为:

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

此外,您缺少 Application.routes.draw do 语句的最终结尾。

于 2011-02-27T23:00:29.563 回答