From b2b9a7a188c98a23db063a7c650d05964bffdbb8 Mon Sep 17 00:00:00 2001 From: ohsab Date: Wed, 26 Nov 2014 11:58:51 +0100 Subject: [PATCH] clean up --- app/controllers/orders_controller.rb | 4 ++-- app/controllers/products_controller.rb | 4 +++- app/controllers/users_controller.rb | 19 +++++++++++++++++++ app/views/layouts/_header.html.erb | 14 +++++++++----- app/views/orders/new.html.erb | 10 +--------- app/views/products/index.html.erb | 4 +++- app/views/users/index.html.erb | 4 +++- app/views/users/show.html.erb | 3 +++ 8 files changed, 43 insertions(+), 19 deletions(-) diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index dbf0edb..0c974ce 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -5,14 +5,14 @@ class OrdersController < ApplicationController def new - @user = User.find(params[:id]) + @user = User.find(params[:user_id]) @order = @user.orders.build @products = Product.all end def create - @user = User.find(params[:id]) + @user = User.find(params[:user_id]) @order = @user.orders.build(order_params) if @order.save #flash[:success] = "order created!" diff --git a/app/controllers/products_controller.rb b/app/controllers/products_controller.rb index cd1d2bc..d376414 100644 --- a/app/controllers/products_controller.rb +++ b/app/controllers/products_controller.rb @@ -33,7 +33,9 @@ class ProductsController < ApplicationController end end - def delete + def destroy + Product.find(params[:id]).destroy + redirect_to products_path end private diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 354e835..8b43342 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -17,10 +17,29 @@ class UsersController < ApplicationController end end + def edit + @user = User.find(params[:id]) + end + + def update + @user = User.find(params[:id]) + if @user.update_attributes(user_params) + redirect_to @user + else + render 'edit' + end + end + def index @users = User.all end + + def destroy + User.find(params[:id]).destroy + redirect_to users_path + end + private def user_params diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 869a955..9549175 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -8,7 +8,6 @@