Skip to content

Instantly share code, notes, and snippets.

@xdougx
Created February 2, 2016 17:45
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 xdougx/e22dd3ee5a3840365e72 to your computer and use it in GitHub Desktop.
Save xdougx/e22dd3ee5a3840365e72 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
layout 'application'
end
class CategoriesController < ApplicationController
# app/views/categories/show.html.erb
def show
@category = Category.find(params[:id])
end
end
class SubCategoriesController < ApplicationController
# app/views/subcategories/show.html.erb
def show
@subcategory = SubCategory.find(params[:id])
end
end
class ProductController < ApplicationController
# app/views/products/show.html.erb
def show
@product = Product.find(params[:id])
end
end
# helpers/menu_helper.rb
module MenuHelper
def categories_menu
content_for(:ul) do
Category.all.map do |category|
content_for(li) do
link_to(category.name, category_path(category))
end
end
end.html_safe
end
def subcategories_menu
content_for(:ul) do
SubCategory.all.map do |subcategory|
content_for(li) do
link_to(subcategory.name, category_subcategory_path(subcategory.id, subcategory.category_id))
end
end
end.html_safe
end
end
<section>
<!-- Monta a Tela -->
</section>
<section>
<div>
<h1><%= @product.name%></h1>
<h3>SubCategories</h3>
<!-- montaa tela -->
</div>
</section>
<!DOCTYPE html>
<html>
<head>
<title>Meu APP</title>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
<%= csrf_meta_tags %>
</head>
<body>
<nav id="menu_esquerda">
<%= categories_menu %>
</nav>
<div class="content">
<%= yield %>
<div>
<nav id="menu_direita">
<%= categories_menu %>
</nav>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment