ruby-on-railsnavigationzurb-foundationcomfortable-mexican-sofa

Creating navigation from pages with ComfortableMexicanSofa and Foundation


I'm building my first web application using Ruby on Rails (v4.1.5), ComfortableMexicanSofa (v1.12.2) for CMS features and admin interface and Foundation 5 for the front-end.

To set up Foundation for Rails, I followed this guide, which created the files _navigation.html.erb and _navigation_links.html.erb in /app/views/layouts, amongst other files.

In the official documentation for ComfortableMexicanSofa, there is this brief guide on how to create a navigation menu from CMS pages. Unfortunately, due to lack of experience, I'm not able to comprehend it.

Relevant excerpt from the documentation:

Generally you would have something like this in your helper/partial:

- @cms_site.pages.root.children.published.each do |page|
  = link_to page.label, page.full_path

Then you can use that from the application layout, or CMS layout/page via a tag.

To my understanding, I need to create some kind of helper in /app/helpers, where I need to to retrieve the CMS pages and serve them to my view, but I'm not sure how to implement this cleanly with Foundation.

Any advice and examples that could point me in the right direction would be greatly appreciated.


Solution

  • You could put something like this in a view or partial:

      <nav class="navbar navbar-default" role="navigation">
        <ul class="nav navbar-nav">
          <li><%= link_to 'Home', '/' %></li>
          <% Comfy::Cms::Site.first.pages.root.children.published.each do |page| %>
            <li><%= link_to page.label, page.full_path %></li>
          <% end %>
        </ul>
      </nav>