Skip to content

Instantly share code, notes, and snippets.

@StefanWallin
Created December 9, 2015 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StefanWallin/ae2f9b9ea122da58fc98 to your computer and use it in GitHub Desktop.
Save StefanWallin/ae2f9b9ea122da58fc98 to your computer and use it in GitHub Desktop.
Recursive cells — is it possible?
<%= render_cell(:menu, :show, { contents: @menu_content }) %>
class MenuCell < Cell::Rails
include Cell::Rails::ViewModel
include ApplicationHelper
def show opts = {}
@options = default_params.merge(opts)
@options[:contents] = JSON.parse(@options[:contents])
render
end
def default_params
{
contents: "[]",
level: 1
}
end
end
<ul>
<%= @options[:contents].each do |item| %>
<li>
<%= item["name"] %>
<% if item.include?("sub_sections") %>
<%= render_cell(
:menu, :show, {
contents: item["sub_sections"],
level: (@options[:level] + 1)
}
) %>
<% end %>
</li>
<% end %>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment