Fix order bug

This commit is contained in:
benji 2015-02-10 08:33:51 +01:00
parent 7642e35d5d
commit 835f08b60c
5 changed files with 22 additions and 6 deletions

View file

@ -45,7 +45,7 @@ class OrdersController < ApplicationController
def quickpay
user = User.find(params[:user_id])
order = user.orders.build
order.products << user.dagschotel
order.order_items << OrderItem.new(count: 1, product: user.dagschotel, order: order)
if order.save
flash[:success] = "Quick pay succeeded. #{view_context.link_to("Undo", [user, order], method: :delete)}."
else

View file

@ -1,6 +1,9 @@
class NotNullFields < ActiveRecord::Migration
def change
def up
change_column :order_items, :product_id, :integer, null: false
change_column :order_items, :order_id, :integer, null: false
end
def down
change_column :order_items, :product_id, :integer, null: true
end
end

View file

@ -1,5 +1,9 @@
class ProductsNamePresenceTrue < ActiveRecord::Migration
def change
def up
change_column :products, :name, :string, null: false
end
def down
change_column :products, :name, :string, null: true
end
end

View file

@ -0,0 +1,9 @@
class OrderIdNullAllowedInOrderItems < ActiveRecord::Migration
def up
change_column :order_items, :order_id, :integer, null: true
end
def down
change_column :order_items, :order_id, :integer, null: false
end
end

View file

@ -11,10 +11,10 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150209145303) do
ActiveRecord::Schema.define(version: 20150210062809) do
create_table "order_items", force: true do |t|
t.integer "order_id", null: false
t.integer "order_id"
t.integer "product_id", null: false
t.integer "count", default: 0
end