Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

edit aside

  • Loading branch information...
commit 134dfdfd8c907a5083797bcf6c2d105515d6340c 1 parent ee97811
@varid007 authored
View
3  store/app/assets/javascripts/categories.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  store/app/assets/stylesheets/categories.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the categories controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
10 store/app/controllers/categories_controller.rb
@@ -0,0 +1,10 @@
+class CategoriesController < ApplicationController
+ def index
+ @categories = Category.all
+ @parent= Category.parent
+ end
+
+ def show
+ @products = Product.find_all_by_category_id(params[:id])
+ end
+end
View
2  store/app/helpers/categories_helper.rb
@@ -0,0 +1,2 @@
+module CategoriesHelper
+end
View
16 store/app/models/category.rb
@@ -1,10 +1,16 @@
class Category < ActiveRecord::Base
has_many :products, :dependent => :destroy
- has_many :categories
-
- has_many :child_categories
-
- belongs_to :parent_category
+
+ has_many :child_categories, :dependent => :destroy,
+ :class_name => "Category",
+ :foreign_key => "parent_id"
+
+ belongs_to :parent_category,
+ :class_name => "Category",
+ :foreign_key => "parent_id"
+
+ scope :parent_category, where("parent_id is NULL ")
+
validates :name, :uniqueness => true,
:presence => true,
:length => {:minimum => 1, :maximum => 15},
View
13 store/app/views/categories/_index.html.erb
@@ -0,0 +1,13 @@
+<% @parent= Category.parent_category %>
+<nav>
+<% @parent.each do |parent| %>
+ <ul>
+ <%= parent.name %>
+ <% parent.child_categories.each do |child| %>
+ <li> <%= link_to child.name, category_path(child.id) %></li>
+ <% end %>
+
+ </ul>
+
+<%end %>
+</nav>
View
14 store/app/views/categories/_index.html.erb~
@@ -0,0 +1,14 @@
+<% @parent= Category.parent %>
+<nav>
+<% @parent.each do |parent|,categories_path %>
+ <ul>
+ <%= parent.name %>
+ <% parent.child_categories.each do |child| %>
+ <li> <%= link_to child.name, category_path(child.id) %></li>
+ <% end %>
+
+ </ul>
+
+<%end %>
+</nav>
+
View
39 store/app/views/categories/show.html.erb
@@ -0,0 +1,39 @@
+<h1>User Products</h1>
+<!-- <p><%= flash[:error] || flash[:notice] %></p> -->
+<p>Products list from DB</p>
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ <th>Price</th>
+ <th>Weight</th>
+ <th>Category</th>
+ </tr>
+ <tr>
+ <% @products.each do |product| %>
+ <td><%= product.name %></td>
+ <td><%= product.description %></td>
+ <td><%= product.price %></td>
+ <td><%= product.weight %></td>
+ <td><%= product.category_id %></td>
+
+ <td>
+ <%= link_to "Show", product_path(product.id) %>
+ <% unless current_user.nil?%>
+ <% if current_user.is_admin? %>
+ <%= link_to "Edit", edit_product_path(product.id) %>
+ <%= link_to 'Delete', product_path(product.id) , confirm: 'Do you want to delete this product?', method: :delete %>
+ <% else%>
+ <% if product.user_id == current_user.id %>
+ <%= link_to "Edit", edit_product_path(product.id) %>
+ <%= link_to 'Delete', product_path(product.id) , confirm: 'Do you want to delete this product?', method: :delete %>
+ <% end %>
+ <%end%>
+ <%end%>
+ </td>
+ </tr>
+ <% end %>
+</table>
+</ul>
+<%= link_to "Create New product", new_product_path %>
+
View
1  store/app/views/layouts/application.html.erb
@@ -32,6 +32,7 @@
<%= render :partial => "home/menu_user"%><br/>
</td>
<% end %>
+ <%= render :partial => "categories/index"%><br/>
<td > <p class="error"><%= flash[:notice]|| flash[:error]%></p><br/><%= yield %></td>
</tr>
</table>
View
23 store/app/views/layouts/application.html.erb~
@@ -7,6 +7,7 @@
<%= javascript_include_tag "jquery-rails.js" %>
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
+ <link rel="stylesheet" type="text/css" href="style.css" />
<%= csrf_meta_tags %>
</head>
<body>
@@ -15,12 +16,24 @@
</div>
<center><h1>Welcome to my store</h1></center>
-
- <center> Home | <%= link_to "Product", products_path %> | <%= link_to "Article", articles_path %> | <%= link_to "Category", admin_categories_path %> </center><br/>
- <table border="1" align="center" width="1000">
+ <hr>
+ <%= link_to "Home", home_index_path %> | <%= link_to "Product", products_path %> | <%= link_to "Article", articles_path %> |
+ <% unless current_user.nil? %>
+ <% if current_user.is_admin %>
+ <%= link_to "Categories", admin_categories_path %> |
+ <% end %>
+ <% end %>
+ <table align="center" width="1000">
<tr>
- <td width="25%">sidebar</td>
- <td> <%= flash[:notice]|| flash[:error]%><%= yield %></td>
+ <td width="25%">
+ <% if (current_user.nil?) %>
+ <%= render :partial => "home/login"%>
+ <% else%>
+ <%= render :partial => "home/menu_user"%><br/>
+ </td>
+ <% end %>
+ <%= render :partial => "index"%><br/>
+ <td > <p class="error"><%= flash[:notice]|| flash[:error]%></p><br/><%= yield %></td>
</tr>
</table>
View
1  store/config/routes.rb
@@ -73,5 +73,6 @@
resources :articles
resources :comments
resources :products
+ resources :categories
resources :home
end
View
7 store/test/functional/categories_controller_test.rb
@@ -0,0 +1,7 @@
+require 'test_helper'
+
+class CategoriesControllerTest < ActionController::TestCase
+ # test "the truth" do
+ # assert true
+ # end
+end
View
4 store/test/unit/helpers/categories_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class CategoriesHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.