3

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.

leifericf
  • 2,324
  • 3
  • 26
  • 37
  • @cms_site and @cms_page get set by the CMS controller so they are already available in your view - if the view is served by CMS. If the view is served by your app's controller then you could do something like: ```@cms_site = Comfy::CMS::Site.first``` like with any other model. – laertiades Sep 01 '14 at 13:01
  • Thanks, @JesseGoodfellow. I hear what you're saying, but unfortunately I don't have enough experience with Rails to be able to understand your comment in the practical terms needed for implementation. If you wouldn't mind, I would greatly appreciate it if you could add an answer and elaborate on your comment, along with some expanded code examples that illustrate what goes where. – leifericf Sep 01 '14 at 17:19

1 Answers1

4

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>
laertiades
  • 1,992
  • 2
  • 19
  • 26
  • Aha, so that's how it's called. I put it in `_nagivation_links.html.erb` and it worked like a charm. That little code example just answered a whole lot of questions. Thanks! :) – leifericf Sep 02 '14 at 06:04