DELETE routes are failing
willian opened this issue · 14 comments
Every time I tried to remove a message or clear all the messages I got this error:
At my router.rb I added:
if Rails.env.development?
mount LetterOpenerWeb::Engine, at: '/letter_opener'
end
And this is what I get when I run rake routes
:
letter_opener_web /letter_opener LetterOpenerWeb::Engine
sidekiq_web /sidekiq Sidekiq::Web
root GET / redirect(301, http://gridleague-dev.com)
Routes for LetterOpenerWeb::Engine:
clear_letters DELETE /clear(.:format) letter_opener_web/letters#clear
delete_letter DELETE /:id(.:format) letter_opener_web/letters#destroy
letters GET / letter_opener_web/letters#index
letter GET /:id(/:style)(.:format) letter_opener_web/letters#show
GET /:id/attachments/:file(.:format) letter_opener_web/letters#attachment
For some reason it calls using POST
but should use DELETE
instead.
Which version are you using? Working fine on 1.2.3
@mmontalvo thank you for your answer, I'm using 1.3.0:
$ bundle list | ag letter
* letter_opener (1.3.0)
* letter_opener_web (1.3.0)
I switched to 1.3.0 and still working. Which browser are you using? Can you please paste some logs?
That failed on Chrome and Safari, the log says:
Started POST "/letter_opener/1438089424_07b115c" for 127.0.0.1 at 2015-07-30 14:02:32 -0300
[Rollbar] Reporting exception: No route matches [POST] "/letter_opener/1438089424_07b115c"
[Rollbar] Scheduling payload
[Rollbar] Sending payload
[Rollbar] Got unexpected status code from Rollbar api: 400
[Rollbar] Response: {
"err": 1,
"message": "access token required"
}
[Rollbar] Details: https://rollbar.com/instance/uuid?uuid=f8da38ee-a731-4d42-b092-f9eac380051b (only available if report was successful)
[Rollbar] Exception uuid saved in env: f8da38ee-a731-4d42-b092-f9eac380051b
ActionController::RoutingError (No route matches [POST] "/letter_opener/1438089424_07b115c"):
.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
.bundle/ruby/2.2.0/gems/rollbar-1.5.3/lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:38:in `call_app'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `block in call'
.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `block in tagged'
.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:26:in `tagged'
.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/tagged_logging.rb:68:in `tagged'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/rack/logger.rb:20:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/request_id.rb:21:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/rack-1.6.0/lib/rack/runtime.rb:18:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/activesupport-4.2.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/rack-1.6.0/lib/rack/lock.rb:17:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/static.rb:113:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/rack-timeout-0.2.4/lib/rack/timeout.rb:108:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/engine.rb:518:in `call'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/application.rb:164:in `call'
.bundle/ruby/2.2.0/gems/newrelic_rpm-3.12.1.298/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
.bundle/ruby/2.2.0/gems/rack-1.6.0/lib/rack/content_length.rb:15:in `call'
.bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:86:in `block in pre_process'
.bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `catch'
.bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:84:in `pre_process'
.bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:53:in `process'
.bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/connection.rb:39:in `receive_data'
.bundle/ruby/2.2.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run_machine'
.bundle/ruby/2.2.0/gems/eventmachine-1.0.7/lib/eventmachine.rb:187:in `run'
.bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/backends/base.rb:73:in `start'
.bundle/ruby/2.2.0/gems/thin-1.6.3/lib/thin/server.rb:162:in `start'
.bundle/ruby/2.2.0/gems/rack-1.6.0/lib/rack/handler/thin.rb:19:in `run'
.bundle/ruby/2.2.0/gems/rack-1.6.0/lib/rack/server.rb:286:in `start'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/commands/server.rb:80:in `start'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:80:in `block in server'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `tap'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:75:in `server'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
.bundle/ruby/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in `<top (required)>'
/bin/rails:4:in `require'
/bin/rails:4:in `<main>'
Rendered .bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.4ms)
Rendered .bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/routes/_route.html.erb (16.2ms)
Rendered .bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/routes/_route.html.erb (3.8ms)
Rendered .bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/routes/_table.html.erb (31.2ms)
Rendered .bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)
Rendered .bundle/ruby/2.2.0/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/routing_error.html.erb within rescues/layout (435.0ms)
I have this problem too. Are there any changes?
I tried gem versions 1.2.3, 1.3.1 and got error in both cases.
api/config/initializers/monkey_patches/letter_opener_web.rb
LetterOpenerWeb::Engine.routes.append do
post 'clear' => 'letters#clear'
post ':id' => 'letters#destroy'
end
Is this still an issue with master?
Adding Rack::MethodOverride
middleware to my application helped with the problem:
# config/environments/development.rb
Rails.application.configure do
# ...
config.middleware.use Rack::MethodOverride
end
About Rack::MethodOverride
from https://guides.rubyonrails.org/rails_on_rack.html:
Allows the method to be overridden if params[:_method] is set. This is the middleware which supports the PUT and DELETE HTTP method types.
An API application is not equipped with it - https://edgeguides.rubyonrails.org/api_app.html#choosing-middleware.
Adding
Rack::MethodOverride
middleware to my application helped with the problem:About `Rack::MethodOverride` from https://guides.rubyonrails.org/rails_on_rack.html:
This was exactly the problem I was facing. I didn't want to pull in that middleware just for a test gem though so I worked around it adding post routes for letters#destroy
and letters#clear
: 793b4e8
Adding
Rack::MethodOverride
middleware to my application helped with the problem:About `Rack::MethodOverride` from https://guides.rubyonrails.org/rails_on_rack.html:This was exactly the problem I was facing. I didn't want to pull in that middleware just for a test gem though so I worked around it adding post routes for
letters#destroy
andletters#clear
: 793b4e8
This solution probably works but this is still an issue since the button for clear
and destroy
on UI is sending a POST
request instead of DELETE
in the version 1.3.4.
Version:
➜ bundle list | grep letter
* letter_opener (1.7.0)
* letter_opener_web (1.3.4)
This solution probably works but this is still an issue since the button for
clear
anddestroy
on UI is sending aPOST
request instead ofDELETE
in the version 1.3.4.
That's fairly normal - web browsers don't support sending a real DELETE from a form - only GET and POST. That's why we have the Rack::MethodOverride middleware. Sending a POST is normal here, it's just that usually with that middleware it is correctly translated back to DELETE on the server-side.
Sorry for the silence here, I might work on this soon #69 (comment)
Use LetterOpenerWeb::Letter.destroy_all
from rails c
untill this bug is fixed.
Hey peeps, as of the 2.0 release that just went out this should no longer be a problem since we now use POST
for everything
letter_opener_web/config/routes.rb
Lines 3 to 9 in e277c97