1

我一直在升级到 Rails 4,并在运行命令“rspec”之后。我收到以下错误:

/Users/lexi87/.rvm/gems/ruby-2.0.0-p0/gems/actionpack-4.0.0.rc1/lib/action_dispatch/routing/mapper.rb:1297:in `member': can't use member outside resource(s) scope (ArgumentError)

我已经稍微改变了我的路线文件,但仍然没有工作。如果有人遇到类似的问题并有解决方法,请与我分享。提前致谢!

Dating::Application.routes.draw do
  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 :sessions
  resources :password_resets
  resources :galleries
  resources :photos
  resources :searches

  resources :questions do
    resources :answers, only: [:new, :create]
  end

  resources :users do  
    member do
      get :settings
  end
end

  root to: 'galleries#index'

  resources :users do |user|
    resources :messages do
      collection do
        post 'delete_multiple'
         get 'settings', on: :member  
      end
    end
  end
4

1 回答 1

2

我认为问题出在这里:

resources :messages do
  collection do
    post 'delete_multiple'
     get 'settings', on: :member  # <--here
  end
end

您不能在集合中定义成员,您应该将其移至资源块,如下所示:

resources :messages do
  collection do
    post 'delete_multiple'
  end
  get 'settings', on: :member
end

请记住,成员路由将需要一个 ID,因为它作用于成员。集合路由不会,因为它作用于对象集合。所以你不能同时使用两者。

于 2013-07-11T16:39:10.877 回答