我一直在升级到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
答案 0 :(得分: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,因为它会对成员起作用。收集路由不是因为它作用于对象集合。 所以你不能同时使用两者。