Determine if path exists as route in Rails controller

后端 未结 5 2005
离开以前
离开以前 2021-01-13 03:57

I want to know if an arbitrary path can be mapped to a route

recognized_request_for accomplishes what I want, but I can\'t get it to work in my controller.

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-13 04:22

    SOLUTION:

    @related_page_path = '/' + @page.path
    begin
      ActionController::Routing::Routes.recognize_path(@related_page_path, :method => :get)
    rescue
      @related_page_path = nil
    end
    

提交回复
热议问题