rails_admin无法编辑和删除:没有路由匹配[POST] / admin / model / id / edit和/ admin / model / id / delete

时间:2016-10-13 14:42:28

标签: ruby-on-rails-5 rails-admin rails-api

开始新的rails 5 api项目,创建模型,添加了rails_admin。我可以在/ admin上看到一个漂亮的管理面板,我可以做除editdelete之外的所有事情。

{"status":404,"error":"Not Found","exception":"#\u003cActionController::RoutingError: No route matches [POST] \"/admin/city/3/edit\"\u003e","traces":{"Application Trace":[],"Framework Trace":[{"id":0,"trace":"actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'"}...]}}
{"status":404,"error":"Not Found","exception":"#\u003cActionController::RoutingError: No route matches [POST] \"/admin/city/3/delete\"\u003e","traces":{"Application Trace":[],"Framework Trace":[{"id":0,"trace":"actionpack (5.0.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:53:in `call'"}...]}}`

我检查了我的路线,并且在EDIT或DELETE

上没有提供实际的POST
Routes for RailsAdmin::Engine:
  dashboard GET         /                                      rails_admin/main#dashboard
      index GET|POST    /:model_name(.:format)                 rails_admin/main#index
        new GET|POST    /:model_name/new(.:format)             rails_admin/main#new
     export GET|POST    /:model_name/export(.:format)          rails_admin/main#export
bulk_delete POST|DELETE /:model_name/bulk_delete(.:format)     rails_admin/main#bulk_delete
bulk_action POST        /:model_name/bulk_action(.:format)     rails_admin/main#bulk_action
       show GET         /:model_name/:id(.:format)             rails_admin/main#show
       edit GET|PUT     /:model_name/:id/edit(.:format)        rails_admin/main#edit
     delete GET|DELETE  /:model_name/:id/delete(.:format)      rails_admin/main#delete
show_in_app GET         /:model_name/:id/show_in_app(.:format) rails_admin/main#show_in_app

1 个答案:

答案 0 :(得分:1)

看到一篇类似的SO帖子here。我认为这是因为rails-5-api删除了api s

不需要的许多中间件

解决方案是在application.rb

中添加此内容
config.middleware.use Rack::MethodOverride