tap/app/controllers/orders_controller.rb

46 lines
850 B
Ruby
Raw Normal View History

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-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-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-24 21:45:32 +01:00
#flash[:success] = "order created!"
2014-11-23 21:12:31 +01:00
end_order
redirect_to overview_path
2014-11-10 02:30:42 +01:00
else
2014-11-25 02:01:57 +01:00
redirect_to root_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
2014-11-25 02:01:57 +01:00
#if params.require(:order).permit(:products)?
2014-11-10 02:30:42 +01:00
params.require(:order).permit(:products)
2014-11-25 02:01:57 +01:00
#{}"products"=>"return_products_string"
2014-11-10 02:30:42 +01:00
end
2014-11-06 18:56:00 +01:00
end