Permalink
Browse files

added a namespace in the routes for admin dashboard

  • Loading branch information...
1 parent 4e0b942 commit f12c830b0f70a66faca04730d555f84c1cbd329b @florida committed Nov 12, 2012
@@ -0,0 +1,83 @@
+class Admin::OrdersController < ApplicationController
+ # GET /orders
+ # GET /orders.json
+ def index
+ @orders = Order.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @orders }
+ end
+ end
+
+ # GET /orders/1
+ # GET /orders/1.json
+ def show
+ @order = Order.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @order }
+ end
+ end
+
+ # GET /orders/new
+ # GET /orders/new.json
+ def new
+ @order = Order.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @order }
+ end
+ end
+
+ # GET /orders/1/edit
+ def edit
+ @order = Order.find(params[:id])
+ end
+
+ # POST /orders
+ # POST /orders.json
+ def create
+ @order = Order.new(params[:order])
+
+ respond_to do |format|
+ if @order.save
+ format.html { redirect_to @order, notice: 'Order was successfully created.' }
+ format.json { render json: @order, status: :created, location: @order }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @order.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /orders/1
+ # PUT /orders/1.json
+ def update
+ @order = Order.find(params[:id])
+
+ respond_to do |format|
+ if @order.update_attributes(params[:order])
+ format.html { redirect_to @order, notice: 'Order was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @order.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /orders/1
+ # DELETE /orders/1.json
+ def destroy
+ @order = Order.find(params[:id])
+ @order.destroy
+
+ respond_to do |format|
+ format.html { redirect_to orders_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -0,0 +1,83 @@
+class Admin::ProductsController < ApplicationController
+ # GET /products
+ # GET /products.json
+ def index
+ @products = Product.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @products }
+ end
+ end
+
+ # GET /products/1
+ # GET /products/1.json
+ def show
+ @product = Product.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @product }
+ end
+ end
+
+ # GET /products/new
+ # GET /products/new.json
+ def new
+ @product = Product.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @product }
+ end
+ end
+
+ # GET /products/1/edit
+ def edit
+ @product = Product.find(params[:id])
+ end
+
+ # POST /products
+ # POST /products.json
+ def create
+ @product = Product.new(params[:product])
+
+ respond_to do |format|
+ if @product.save
+ format.html { redirect_to @product, notice: 'Product was successfully created.' }
+ format.json { render json: @product, status: :created, location: @product }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @product.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /products/1
+ # PUT /products/1.json
+ def update
+ @product = Product.find(params[:id])
+
+ respond_to do |format|
+ if @product.update_attributes(params[:product])
+ format.html { redirect_to @product, notice: 'Product was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @product.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /products/1
+ # DELETE /products/1.json
+ def destroy
+ @product = Product.find(params[:id])
+ @product.destroy
+
+ respond_to do |format|
+ format.html { redirect_to products_url }
+ format.json { head :no_content }
+ end
+ end
+end
@@ -0,0 +1,33 @@
+<%= form_for(@order) do |f| %>
+ <% if @order.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@order.errors.count, "error") %> prohibited this order from being saved:</h2>
+
+ <ul>
+ <% @order.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :first_name %><br />
+ <%= f.text_field :first_name %>
+ </div>
+ <div class="field">
+ <%= f.label :last_name %><br />
+ <%= f.text_field :last_name %>
+ </div>
+ <div class="field">
+ <%= f.label :email %><br />
+ <%= f.text_field :email %>
+ </div>
+ <div class="field">
+ <%= f.label :address %><br />
+ <%= f.text_field :address %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing order</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @order %> |
+<%= link_to 'Back', orders_path %>
@@ -0,0 +1,29 @@
+<h1>Listing orders</h1>
+
+<table>
+ <tr>
+ <th>First name</th>
+ <th>Last name</th>
+ <th>Email</th>
+ <th>Address</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @orders.each do |order| %>
+ <tr>
+ <td><%= order.first_name %></td>
+ <td><%= order.last_name %></td>
+ <td><%= order.email %></td>
+ <td><%= order.address %></td>
+ <td><%= link_to 'Show', order %></td>
+ <td><%= link_to 'Edit', edit_order_path(order) %></td>
+ <td><%= link_to 'Destroy', order, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Order', new_order_path %>
@@ -0,0 +1,5 @@
+<h1>New order</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', orders_path %>
@@ -0,0 +1,25 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>First name:</b>
+ <%= @order.first_name %>
+</p>
+
+<p>
+ <b>Last name:</b>
+ <%= @order.last_name %>
+</p>
+
+<p>
+ <b>Email:</b>
+ <%= @order.email %>
+</p>
+
+<p>
+ <b>Address:</b>
+ <%= @order.address %>
+</p>
+
+
+<%= link_to 'Edit', edit_order_path(@order) %> |
+<%= link_to 'Back', orders_path %>
@@ -0,0 +1,33 @@
+<%= form_for(@product) do |f| %>
+ <% if @product.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
+
+ <ul>
+ <% @product.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <div class="field">
+ <%= f.label :name %><br />
+ <%= f.text_field :name %>
+ </div>
+ <div class="field">
+ <%= f.label :description %><br />
+ <%= f.text_area :description %>
+ </div>
+ <div class="field">
+ <%= f.label :price %><br />
+ <%= f.text_field :price %>
+ </div>
+ <div class="field">
+ <%= f.label :stock_no %><br />
+ <%= f.number_field :stock_no %>
+ </div>
+ <div class="actions">
+ <%= f.submit %>
+ </div>
+<% end %>
@@ -0,0 +1,6 @@
+<h1>Editing product</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Show', @product %> |
+<%= link_to 'Back', products_path %>
@@ -0,0 +1,29 @@
+<h1>Listing products</h1>
+
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Description</th>
+ <th>Price</th>
+ <th>Stock no</th>
+ <th></th>
+ <th></th>
+ <th></th>
+ </tr>
+
+<% @products.each do |product| %>
+ <tr>
+ <td><%= product.name %></td>
+ <td><%= product.description %></td>
+ <td><%= product.price %></td>
+ <td><%= product.stock_no %></td>
+ <td><%= link_to 'Show', product %></td>
+ <td><%= link_to 'Edit', edit_product_path(product) %></td>
+ <td><%= link_to 'Destroy', product, method: :delete, data: { confirm: 'Are you sure?' } %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New Product', new_product_path %>
@@ -0,0 +1,5 @@
+<h1>New product</h1>
+
+<%= render 'form' %>
+
+<%= link_to 'Back', products_path %>
@@ -0,0 +1,25 @@
+<p id="notice"><%= notice %></p>
+
+<p>
+ <b>Name:</b>
+ <%= @product.name %>
+</p>
+
+<p>
+ <b>Description:</b>
+ <%= @product.description %>
+</p>
+
+<p>
+ <b>Price:</b>
+ <%= @product.price %>
+</p>
+
+<p>
+ <b>Stock no:</b>
+ <%= @product.stock_no %>
+</p>
+
+
+<%= link_to 'Edit', edit_product_path(@product) %> |
+<%= link_to 'Back', products_path %>
View
@@ -1,8 +1,7 @@
Elmorfstore::Application.routes.draw do
- resources :orders
-
- resources :products
-
+namespace :admin do
+ resources :orders, :products
+end
# The priority is based upon order of creation:
# first created -> highest priority.

0 comments on commit f12c830

Please sign in to comment.