Class: OrderItemsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- OrderItemsController
- Defined in:
- app/controllers/order_items_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/order_items_controller.rb', line 14 def create @order_item = @order.order_items.find_or_initialize_by_product_id(params[:order_item]) unless @order_item.new_record? @order_item.quantity += params[:order_item][:quantity].to_i end if @order_item.save redirect_to order_url(@order) else render :action => 'new' end end |
#destroy ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/order_items_controller.rb', line 40 def destroy @order_item = OrderItem.find(params[:id]) @order_item.destroy flash[:notice] = "Successfully destroyed order item." respond_to do |format| format.html { redirect_to order_url(@order) } format.js {} end end |
#edit ⇒ Object
26 27 28 |
# File 'app/controllers/order_items_controller.rb', line 26 def edit @order_item = OrderItem.find(params[:id]) end |
#index ⇒ Object
2 3 4 |
# File 'app/controllers/order_items_controller.rb', line 2 def index @order_items = OrderItem.all end |
#new ⇒ Object
10 11 12 |
# File 'app/controllers/order_items_controller.rb', line 10 def new @order_item = OrderItem.new end |
#show ⇒ Object
6 7 8 |
# File 'app/controllers/order_items_controller.rb', line 6 def show @order_item = OrderItem.find(params[:id]) end |
#update ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/order_items_controller.rb', line 30 def update @order_item = OrderItem.find(params[:id]) if @order_item.update_attributes(params[:order_item]) flash[:notice] = "Successfully updated order item." redirect_to @order_item else render :action => 'edit' end end |