2014-11-06 18:56:00 +01:00
|
|
|
class OrdersController < ApplicationController
|
|
|
|
def new
|
2014-11-23 21:12:31 +01:00
|
|
|
@users = User.all
|
2014-11-06 18:56:00 +01:00
|
|
|
end
|
|
|
|
|
2014-11-23 21:12:31 +01:00
|
|
|
def create_session
|
|
|
|
user = User.find(params[:user_id])
|
|
|
|
if user
|
|
|
|
ordering(user)
|
|
|
|
redirect_to order_path
|
|
|
|
else
|
|
|
|
redirect_to overview_path
|
|
|
|
end
|
2014-11-10 02:30:42 +01:00
|
|
|
end
|
|
|
|
|
2014-11-23 21:12:31 +01:00
|
|
|
def order
|
|
|
|
@order = current_ordering_user.orders.build
|
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-23 21:12:31 +01:00
|
|
|
@order = current_ordering_user.orders.build(order_params)
|
2014-11-10 02:30:42 +01:00
|
|
|
if @order.save
|
2014-11-23 21:12:31 +01:00
|
|
|
flash[:success] = "order created!"
|
|
|
|
end_order
|
|
|
|
redirect_to overview_path
|
2014-11-10 02:30:42 +01:00
|
|
|
else
|
2014-11-23 21:12:31 +01:00
|
|
|
redirect_to overview_path
|
2014-11-10 02:30:42 +01:00
|
|
|
end
|
2014-11-06 18:56:00 +01:00
|
|
|
end
|
2014-11-10 02:30:42 +01:00
|
|
|
|
2014-11-23 21:12:31 +01:00
|
|
|
def destroy
|
|
|
|
end_order
|
|
|
|
redirect_to overview_path
|
|
|
|
end
|
|
|
|
|
2014-11-10 02:30:42 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def order_params
|
|
|
|
params.require(:order).permit(:products)
|
|
|
|
end
|
2014-11-06 18:56:00 +01:00
|
|
|
end
|