如何在 VoltRb 中访问页面的 URL
How to access a page's URL in VoltRb
我正在尝试 运行 在 Volt 的控制器上编写一些代码,但仅限于某些页面。我查看了文档,但我不太确定如何访问给定页面的 URL。在 page
模型中是否有一些隐藏变量或其他东西,像这样?:
module Main
class MyController < Volt::ModelController
model :page
def index
end
def template_page
if page.url == "/foo/bar" # obviously, this doesn't actually work
# run some code
end
end
end
end
如果您在 URL 中使用绑定,例如
client '/examples/{{ category }}/{{ example }}', controller: 'examples', action: 'template'
您可以通过参数集合访问控制器中的那些:
params._category
params._example
在其他情况下,您 URL 无论如何都应该是静态的。
抱歉回复晚了。我为控制器提供的 url
方法添加了文档:
我正在尝试 运行 在 Volt 的控制器上编写一些代码,但仅限于某些页面。我查看了文档,但我不太确定如何访问给定页面的 URL。在 page
模型中是否有一些隐藏变量或其他东西,像这样?:
module Main
class MyController < Volt::ModelController
model :page
def index
end
def template_page
if page.url == "/foo/bar" # obviously, this doesn't actually work
# run some code
end
end
end
end
如果您在 URL 中使用绑定,例如
client '/examples/{{ category }}/{{ example }}', controller: 'examples', action: 'template'
您可以通过参数集合访问控制器中的那些:
params._category
params._example
在其他情况下,您 URL 无论如何都应该是静态的。
抱歉回复晚了。我为控制器提供的 url
方法添加了文档: