我有一个 Roda API,所有资源都提取到独立应用程序中,并作为机架应用程序添加到主路由器,使用r.run SubApp
. 但是我必须在另一个文件中使用一个文件中的参数。以此为例:
# api/api.rb
class Api < Roda
route do |router|
router.on "api" do
router.on "v1" do
router.on "users" do
router.run UserApp
end
end
end
end
end
# api/user_app.rb
class UserApp < Roda
route do |router|
router.is do
# ....
end
router.on String do |identifier| # <--- this parameter
router.is do
# ...
end
# Branch: /api/v1/users/:identifier/comments
router.on "roles" do
router.run CommentApp # How to pass identifier inside??
end
end
end
end
# api/comments_app.rb
class CommentApp < Roda
# ...
# <---- here I need `identifier` value
end