tap/app/controllers/orders_controller.rb

37 lines
688 B
Ruby
Raw Normal View History

2014-11-06 17:56:00 +00:00
class OrdersController < ApplicationController
2014-11-25 14:27:12 +00:00
def overview
2014-11-23 20:12:31 +00:00
@users = User.all
2014-11-06 17:56:00 +00:00
end
2014-11-10 01:30:42 +00:00
2014-11-25 14:27:12 +00:00
def new
2014-11-26 10:58:51 +00:00
@user = User.find(params[:user_id])
2014-11-25 14:27:12 +00:00
@order = @user.orders.build
2014-11-24 20:45:32 +00:00
@products = Product.all
2014-12-04 16:02:08 +00:00
@order_products = @order.order_products
@products.each do |p|
@order.order_products.build(product: p)
end
2014-11-06 17:56:00 +00:00
end
2014-11-23 20:12:31 +00:00
2014-11-06 17:56:00 +00:00
def create
2014-11-26 10:58:51 +00:00
@user = User.find(params[:user_id])
2014-12-04 16:02:08 +00:00
@order = @user.orders.build
@products = Product.all
@order_products = @order.order_products
2014-11-10 01:30:42 +00:00
2014-12-04 16:02:08 +00:00
@products.each do |p|
@order.order_products.build(product: p)
2014-11-25 14:27:12 +00:00
end
2014-12-04 16:02:08 +00:00
render 'new'
2014-11-23 20:12:31 +00:00
end
2014-11-10 01:30:42 +00:00
private
def order_params
2014-12-04 16:02:08 +00:00
params.require(:order).permit(:products)
2014-11-10 01:30:42 +00:00
end
2014-11-06 17:56:00 +00:00
end