有没有办法将地图和(莲花)路由器命名空间一起使用?下面是config.ru我试图作为演示运行的示例.
require 'bundler'
Bundler.require
module Demo
class Application
def initialize
@app = Rack::Builder.new do
map '/this_works' do
run Proc.new {|env| [200, {"Content-Type" => "text/html"}, ["this_works"]]}
end
map '/api' do
run Lotus::Router.new do
get '/api/', to: ->(env) { [200, {}, ['Welcome to Lotus::Router!']] }
get '/*', to: ->(env) { [200, {}, ["This is catch all: #{ env['router.params'].inspect }!"]] }
end
end
end
end
def call(env)
@app.call(env)
end
end
end
run Demo::Application.new
Run Code Online (Sandbox Code Playgroud) 我有hanami应用程序版本1.0.0我有下一个routes.rb文件:
get '/games', to: 'games#index'
root to: 'home#index'
Run Code Online (Sandbox Code Playgroud)
我阅读了文档并尝试使用
<%= routes.games_path %>
Run Code Online (Sandbox Code Playgroud)
在application.html.erb模板中,但收到了下一个错误:
Hanami :: Routing :: InvalidRouteException:没有为游戏生成路径(路径) - 请检查给定的参数
如何在hanami模板中使用路由器?
那天我发现了Hanami(Hanami 1.3),正在完善我从事的测试项目,但找不到从视图或模板访问当前页面url /路径的方法(这个想法如您所料,正在处理导航链接的可视状态。
我试着猜助手名(routes.current_page,routes.current_url,routes.current...),但我没有很幸运的。我已经检查了路由帮助程序文档,遍历了hanami / hanami和hanami / router存储库,但没有找到我想要的东西。
我是否想念某些东西,或者这根本不是内置的?