2014-11-06 18:56:00 +01:00
|
|
|
class OrdersController < ApplicationController
|
2014-11-25 15:27:12 +01:00
|
|
|
def overview
|
2014-11-23 21:12:31 +01:00
|
|
|
@users = User.all
|
2014-11-06 18:56:00 +01:00
|
|
|
end
|
|
|
|
|
2014-11-10 02:30:42 +01:00
|
|
|
|
2014-11-25 15:27:12 +01:00
|
|
|
def new
|
|
|
|
@user = User.find(params[:id])
|
|
|
|
@order = @user.orders.build
|
2014-11-24 21:45:32 +01:00
|
|
|
@products = Product.all
|
2014-11-06 18:56:00 +01:00
|
|
|
end
|
|
|
|
|
2014-11-23 21:12:31 +01:00
|
|
|
|
2014-11-06 18:56:00 +01:00
|
|
|
def create
|
2014-11-25 15:27:12 +01:00
|
|
|
@user = User.find(params[:id])
|
|
|
|
@order = @user.orders.build(order_params)
|
2014-11-10 02:30:42 +01:00
|
|
|
if @order.save
|
2014-11-24 21:45:32 +01:00
|
|
|
#flash[:success] = "order created!"
|
2014-11-23 21:12:31 +01:00
|
|
|
redirect_to overview_path
|
2014-11-10 02:30:42 +01:00
|
|
|
else
|
2014-11-25 15:27:12 +01:00
|
|
|
@products = Product.all
|
|
|
|
render 'new'
|
2014-11-10 02:30:42 +01:00
|
|
|
|
2014-11-25 15:27:12 +01:00
|
|
|
end
|
2014-11-23 21:12:31 +01:00
|
|
|
end
|
|
|
|
|
2014-11-10 02:30:42 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def order_params
|
2014-11-25 16:13:04 +01:00
|
|
|
#params.require(:order).permit(:products)
|
|
|
|
#
|
2014-11-10 02:30:42 +01:00
|
|
|
end
|
2014-11-06 18:56:00 +01:00
|
|
|
end
|