rails_admin: Can not edit or create new records in rails admin
I have a problem with crating and updating records with rails_admin. For update I get the 404 error, where POST actions is not found:
{"status":404,"error":"Not Found","exception":"#\u003cActionController::RoutingError: No route matches [POST] \"/admin/api_key/1/edit\"....
But if i look in the routes file, i see it’s registered at PUT method.
For creating new record i get:
{"status":422,"error":"Unprocessable Entity","exception":"#\u003cActionController::InvalidAuthenticityToken: ActionController::InvalidAuthenticityToken\u003e","traces":{"Application Trace":[],"Framewor....
my config file:
RailsAdmin.config do |config| config.actions do dashboard # mandatory index # mandatory new export bulk_delete show edit delete show_in_app end end
my route setting:
Rails.application.routes.draw do mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 10
- Comments: 16 (2 by maintainers)
Commits related to this issue
- [Security] Fixes CSRF vulnerability, introduced by 53eef4fe2ec0953381f4e3197c885adc0423dd49 Reported by SourceClear, Inc. — committed to railsadminteam/rails_admin by mshibuya 8 years ago
I just upgraded from Rails 5.0.0 to 5.1.0 because of this error and the problem still persists (in development). I’m running Puma locally not Nginx.
Adding new records:
Downgrading to RailsAdmin 1.1.0 solved the first issue but not the second - I still can’t update records.
rails routes
shows this:UPDATE: I switched to the Administrate gem and had the same issues! The authenticity_token issue was caused by Rails Api leaving out the cookie store, I was able to fix this by adding some lines to
application.rb
:The routing issue was caused by the MethodOverride Rack middleware being left out - so when Rails receives forms with the hidden
_method
parameter set toPATCH
it doesn’t act on that. To fix that I added this toapplication.rb
:These workarounds work with both Administrate and RailsAdmin 1.2.0.
@lesliev Dude, you saved my day. This solution works for both issues as advertised ! Thanks a lot.