ruby on rails - Why is my catch-all route not working for some routes? -
i have in routes.rb:
resources :emergencies, except: [:new, :edit, :destroy], defaults: { format: :json } match '*path', to: 'application#page_not_found', via: :all i have in application.rb:
config.exceptions_app = self.routes and application_controller.rb looks this:
class applicationcontroller < actioncontroller::base def page_not_found render json: { message: 'page not found' }, status: :not_found end end i have set of test suites tests :new, :edit, , :destroy route. routes :edit , :destroy pass, returning message page not found expected, :new route returns null. infact, /emergencies/anything render null, /emergences/new/new work correctly. idea on why happening , how can fix route /emergencies/new hitting page_not_found action?
run rake routes see how routes lay out.
you notice show route matches emergencies/:id (this includes emergencies/new, example).
routes match top down. normally, resources declare new route before show route, catch match future declarations.
if can, add constraint show route, if not match id, @ least not match new. or keep resource routes , kick them page_not_found method in before_filter in controller...
Comments
Post a Comment