1

我正在尝试在 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
4

2 回答 2

2

例如,如果您在 URL 中使用绑定

client '/examples/{{ category }}/{{ example }}', controller: 'examples', action: 'template'

您可以通过 params 集合访问控制器中的那些:

params._category
params._example

在其他情况下,您的 URL 无论如何都应该是静态的。

于 2015-06-25T06:11:07.523 回答
1

这么晚才回复很抱歉。我为url控制器提供的方法添加了文档:

http://docs.voltframework.com/en/docs/url.html

于 2015-06-26T04:04:02.023 回答