ruby-on-railsroutesurl-routinghigh-voltage

Using high voltage with nested directories


I have a rails 3.2 application in which I am using the gem High Voltage for my public pages. It seems to work fine, however, I would like to be able to put some subdirectories in my pages folder.

For example:

/pages
--/directory_1
----index.html.erb
--/directory_2
----index.html.erb

In this example, I want to point my browser to pages/directory_1/index, etc. The documentation claims it to be possible:

You can nest pages in a directory structure, if that makes sense from a URL perspective for you: link_to "Q4 Reports", page_path("about/corporate/policies/HR/en_US/biz/sales/Quarter-Four")

But something like that doesn't work for me.

I have tried it with a namespace:

namespace :directory_1 do
  match "pages/:id" => "high_voltage/pages#show"
end

but that of course then goes to directory_1/high_voltage/pages#show, which is wrong.

Simply doing match "pages/directory_1/:id" => "high_voltage/pages#show" comes with two problems: It does not allow for any views in the pages directory itself anymore, and views with the same filename in different subdirectories will get confused.

So how can I accomplish nested directories inside my pages directory with High Voltage?


Solution

  • Simply create a directory structure inside app/views/pages to reflect the URL hierarchy that you need.

    For instance, if you created a view named about.html.erb with the path app/views/pages/about_me/about.html.erb, you will reference it by using

    <%= link_to "About", page_path("about_me/about") %>
    

    I got this exact solution working in a current project.