我试图在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发布于 2015-06-25 06:11:07
如果在URL中使用绑定,例如
client '/examples/{{ category }}/{{ example }}', controller: 'examples', action: 'template'您可以通过params集合访问控制器中的那些内容:
params._category
params._example在其他情况下,您的URL无论如何应该是静态的。
发布于 2015-06-26 04:04:02
抱歉,回复晚了。我为url方法添加了文档,该方法可从控制器获得:
http://docs.voltframework.com/en/docs/url.html
https://stackoverflow.com/questions/31034666
复制相似问题