🖥
#Rails error handling : routing not existence all path with request m
Warning
do not use easy
How
match '*path', to: 'errors#not_found', via: :all
or describe each request types
get '*path', to: 'errors#not_found'
post '*path', to: 'errors#not_found'
put '*path', to: 'errors#not_found'
patch '*path', to: 'errors#not_found'
delete '*path', to: 'errors#not_found'
match '*path', to: 'errors#not_found', via: :options
rspec test example
require 'rails_helper'
describe 'not found path', type: :request do
describe 'get' do
subject { get "/path/to/not/existence/" }
before { subject }
it { expect(response.status).to eq 404 }
end
describe 'post' do
subject { post "/path/to/not/existence/" }
before { subject }
it { expect(response.status).to eq 404 }
end
describe 'put' do
subject { put "/path/to/not/existence/" }
before { subject }
it { expect(response.status).to eq 404 }
end
describe 'patch' do
subject { patch "/path/to/not/existence/" }
before { subject }
it { expect(response.status).to eq 404 }
end
describe 'delete' do
subject { delete "/path/to/not/existence/" }
before { subject }
it { expect(response.status).to eq 404 }
end
context 'options' do
subject { process :options, "/path/to/not/existence/" }
before { subject }
it { expect(response.status).to eq 404 }
end
end
REf
Railsの ActionController::RoutingError は ApplicationController での rescue_from で捕まえられない - Qiita
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。
公開日時
2019-12-01
Discussion