Unexpected behaviour with traling slash

6 views
Skip to first unread message

Stephen Paul Weber

unread,
Sep 22, 2021, 5:10:38 PMSep 22
to Roda
route do |r|
  r.on "register" do
    r.on "boop" do
      r.get "wut" do
        "wut"
       end

     r.get do
       "boop"
      end
    end
  end
end

This code seems to result in the "register" block being run for both /register/boop and /register/boop/  I would have expected it to match only one of those...

Jeremy Evans

unread,
Sep 22, 2021, 11:13:33 PMSep 22
to ruby...@googlegroups.com
The `r.on "register"` block will run for requests starting with /register.  The `r.on "boop"` block inside that will run for requests starting with /register/boop.  If the request is a GET request for /register/boop/wut, it will return "wut".  If the request is any other GET request starting with /register/boop (including /register/boop, /register/boop/, and /register/boop/anything/else), it runs "boop".  You may want to change the `r.get` call to `r.get true` so that it only matches GET requests for /register/boop, and not other GET requests starting with /register/boop.  The true argument to r.get triggers a terminal match (r.get without arguments does not force a terminal match).

Thanks,
Jeremy
Reply all
Reply to author
Forward
0 new messages