imjp
imjp

Reputation: 6695

Table is not being created for some reason

I ran the following commands:

rails generate scaffold order name:string address:text email:string pay_type:string   
rails generate migration add_order_id_to_line_item order_id:integer    
rake db:migrate

For some reason db/schema.db doesn't show the orders table. I even tried placing it manually in the schema.db and migrating again but I still cannot access /orders :(

Anyone have any idea what might be causing this?

Page access errors: https://i.sstatic.net/5C3Rm.jpg
Migration outputs: https://i.sstatic.net/936k8.jpg

https://github.com/imjp/shop

Upvotes: 1

Views: 263

Answers (1)

Joey
Joey

Reputation: 455

Your migration file 20110623001141_combine_items_in_cart.rb does not have the proper class wrapper, in addition it has methods inside it that shouldn't be there.

class CombineItemsInCart < ActiveRecord::Migration
    def self.up
        # replace multiple items for a single product in a cart with a single item
        Cart.all.each do |cart|
        # count the number of each product in the cart
            sums = cart.line_items.group(:product_id).sum(:quantity)

            sums.each do |product_id, quantity|
                if quantity >1
                    # remove individual items
                    cart.line_items.where(:product_id=>product_id).delete_all

                    # replace with a single item
                    cart.line_items.create(:product_id=>product_id, :quantity=>quantity)
                end
            end
        end
    end

    def self.down
        # split items with quantity>1 into multiple items
        LineItem.where("quantity>1").each do |line_item|
            # add individual items
            line_item.quantity.times do
                LineItem.create :cart_id=>line_item.cart_id,
                                :product_id=>line_item.product_id, :quantity=>1
            end

            # remove original item
            line_item.destroy
        end``
    end
end

You also seem to have a duplicate inside 20110626203934_add_oder_to_line_item.rb which is adding a column already added by 20110626181924_add_order_id_to_line_item.rb. Delete either one and try your migration again.

Upvotes: 2

Related Questions