Determine if path exists as route in Rails controller

后端 未结 5 1976
离开以前
离开以前 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:11

    If you want to connect an arbitrary path the a controller and and action, you can use map.connect

    map.connect '/any/random/string/of/stuff', :controller => 'items', :action => 'new'
    

    You can even call out embedded param designations in the path:

    map.connect '/seeking/room/for/[:number_of_nights]/nights', :controller => 'rooms', :action => 'index'
    

    with the above you will receive the value represented in the url as part of the params hash in the controller.

提交回复
热议问题