How to access a page's URL in VoltRb

62 views Asked by At

I'm trying to run some code on a controller in Volt, but only on certain pages. I've looked through the docs, but I'm not really sure how to get access to a given page's URL. Is there perhaps some hidden variable or something in the page model, like so?:

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
2

There are 2 answers

0
Julian Fahrer On BEST ANSWER

If you are using bindings in your URL, for example

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

you can access those in the controller via the params collection:

params._category
params._example

In other cases you URL should be static anyway.

1
Ryan On

Sorry for the late reply. I added docs for the url method which is available from controllers:

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