Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在ruby中删除前验证对象集合_Ruby On Rails_Ruby_Web Applications - Fatal编程技术网

Ruby on rails 在ruby中删除前验证对象集合

Ruby on rails 在ruby中删除前验证对象集合,ruby-on-rails,ruby,web-applications,Ruby On Rails,Ruby,Web Applications,我试图只允许删除,如果有多个用户的角色“所有者”。我想显示一条错误消息,如果用户(具有角色所有者)是唯一所有者,则他们无法删除该用户。这就是这张桌子的样子 这是我的破坏方法 发生的情况是,我试图重定向,但我收到了错误 Started DELETE "/teams" for ::1 at 2017-07-26 11:45:28 -0400 ActionController::RoutingError (No route matches [DELETE] "/teams"): actionp

我试图只允许删除,如果有多个用户的角色“所有者”。我想显示一条错误消息,如果用户(具有角色所有者)是唯一所有者,则他们无法删除该用户。这就是这张桌子的样子

这是我的破坏方法

发生的情况是,我试图重定向,但我收到了错误

Started DELETE "/teams" for ::1 at 2017-07-26 11:45:28 -0400

ActionController::RoutingError (No route matches [DELETE] "/teams"):
  actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.3) lib/rails/engine.rb:518:in `call'
  railties (4.2.3) lib/rails/application.rb:165:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  puma (3.9.1) lib/puma/configuration.rb:224:in `call'
  puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
  puma (3.9.1) lib/puma/server.rb:435:in `process_client'
  puma (3.9.1) lib/puma/server.rb:299:in `block in run'
  puma (3.9.1) lib/puma/thread_pool.rb:120:in `call'
  puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'


  Rendered /Users/kristianquincosa/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.7ms)
  Rendered /Users/kristianquincosa/.rvm/gems/ruby-2.2.3/gems/actionpack-4.2.3/lib/action_dispatch/middleware/templates/rescues/routing_error.text.erb (18.7ms)
收到错误后,记录不会删除,但错误消息不会闪烁,但页面会重定向。当我刷新页面时,我会看到错误消息。请帮忙,谢谢

编辑

这是删除的代码

link_to('', team_path(user), method: :delete, data: {confirm: "Are you sure you want to delete this member?"}, :remote => true, class: "btn btn-danger fa fa-trash delete_user")
这是我的路线

teams GET    /teams(.:format)                                         teams#index
                                         POST   /teams(.:format)                                         teams#create
                                new_team GET    /teams/new(.:format)                                     teams#new
                               edit_team GET    /teams/:id/edit(.:format)                                teams#edit
                                    team PATCH  /teams/:id(.:format)                                     teams#update
                                         PUT    /teams/:id(.:format)                                     teams#update
                                         DELETE /teams/:id(.:format)                                     teams#destroy

尝试更改
respond\u to
代码块中的
redirect\u to teams\u path
redirect\u to teams\u url

尝试更改
redirect\u to teams\u path
redirect\u to teams\u url
代码块中的
至teams\u url

要删除的链接错误。您可以编辑您的问题并添加相关的视图代码吗?屏幕截图没有提供信息。Ruby还强烈鼓励使用仅小写的变量和方法名称,因此
lastOwner
应该是
last\u owner
。这是因为case在Ruby中有意义,常量的前缀是大写字母。您的
config/routes.rb
看起来怎么样?如何生成“删除”按钮?@tadman我添加了代码,谢谢。@spickermann添加了我的路线您要删除的链接是错误的。您可以编辑您的问题并添加相关的视图代码吗?屏幕截图没有提供信息。Ruby还强烈鼓励使用仅小写的变量和方法名称,因此
lastOwner
应该是
last\u owner
。这是因为case在Ruby中有意义,常量的前缀是大写字母。您的
config/routes.rb
看起来怎么样?如何生成删除按钮?@tadman我添加了代码,谢谢。@spickermann添加了我的路由
teams GET    /teams(.:format)                                         teams#index
                                         POST   /teams(.:format)                                         teams#create
                                new_team GET    /teams/new(.:format)                                     teams#new
                               edit_team GET    /teams/:id/edit(.:format)                                teams#edit
                                    team PATCH  /teams/:id(.:format)                                     teams#update
                                         PUT    /teams/:id(.:format)                                     teams#update
                                         DELETE /teams/:id(.:format)                                     teams#destroy