2010-10-08 25 views
2

編輯:這是使用Rails 2.3.5獲得一個「有沒有指定的列」當裝載Rails的燈具

出於某種原因,當我嘗試與樂隊信用卡式在我的項目聯繫起來,我得到以下錯誤

SQLite3::SQLException: table credit_cards has no column named band: INSERT INTO "credit_cards" ("created_at", "vault_token", "billing_zipcode", "billing_first_name", "updated_at", "band", "billing_state", "billing_city", "id", "billing_email_address", "billing_country", "billing_address", "billing_phone_number", "billing_last_name") VALUES ('2010-10-08 03:26:07', 'vaulttokenvalue', 12345, 'Test', '2010-10-08 03:26:07', 'beekin', 'TX', 'AnyCity', 714867248, '[email protected]', 'US', '1234 Any Street', '5555555555', 'User') 

SQLite3::SQLException: table bands has no column named credit_card: INSERT INTO "bands" ("name", "created_at", "next_payment_date", "updated_at", "credit_card", "account_type_id", "id", "hometown_city", "account_status", "subdomain", "hometown_state", "website", "account_type_name") VALUES ('Beekin', '2010-10-08 03:29:16', '2010-10-07', '2010-10-08 03:29:16', 'card_one', 715507355, 862144657, 'Nashville', 'ACTIVE', 'beekin', 'TN', 'http://www.beekin.com', 'MONTHLY') 

我的遷移看起來像

class CreateCreditCards < ActiveRecord::Migration 
    def self.up 
    create_table :credit_cards do |t| 
     t.references :band 
     t.string :billing_first_name 
     t.string :billing_last_name 
     t.string :billing_address 
     t.string :billing_city 
     t.string :billing_state 
     t.string :billing_zipcode 
     t.string :billing_country 
     t.string :billing_email_address 
     t.string :billing_phone_number 
     t.string :vault_token 

     t.timestamps 
    end 

    add_column :bands, :credit_card_id, :integer 
    end 
end 

我bands.yml夾具的樣子:

beekin: 
    name: Beekin 
    website: "http://www.beekin.com" 
    hometown_city: Nashville 
    hometown_state: TN 
    subdomain: beekin 
    account_type: monthly 
    account_type_name: "MONTHLY" 
    account_status: "ACTIVE" 
    credit_card: card_one 
    next_payment_date: <%= Date.today %> 

而且我credit_cards.yml夾具的樣子:

card_one: 
    band: beekin 
    billing_first_name: Test 
    billing_last_name: User 
    billing_address: "1234 Any Street" 
    billing_city: AnyCity 
    billing_state: TX 
    billing_zipcode: 12345 
    billing_country: US 
    billing_email_address: "[email protected]" 
    billing_phone_number: "5555555555" 
    vault_token: vaulttokenvalue 

能有人請指出我在做什麼錯。我已經將它與其他燈具進行了比較,它看起來應該可以工作,但事實並非如此。

has_ has_one:credit_card(帶內模型)和belongs_to:band(在credit_card模型中)。我現在真的很失落。

回答

0
card_one: 
    band_id: 1 //or any other Band id 
    billing_first_name: Test 
    billing_last_name: User 
    billing_address: "1234 Any Street" 
    billing_city: AnyCity 
    billing_state: TX 
    billing_zipcode: 12345 
    billing_country: US 
    billing_email_address: "[email protected]" 
    billing_phone_number: "5555555555" 
    vault_token: vaulttokenvalue 

beekin: 
    name: Beekin 
    website: "http://www.beekin.com" 
    hometown_city: Nashville 
    hometown_state: TN 
    subdomain: beekin 
    account_type: monthly 
    account_type_name: "MONTHLY" 
    account_status: "ACTIVE" 
    credit_card_id: 1 // or any other Card id 
    next_payment_date: <%= Date.today %> 
+3

我敢肯定,你不要以爲一個id分配給固定,因爲你不知道插入數據庫時​​,某個夾具的ID會是什麼。 – Koby 2010-10-08 11:27:31

+0

我還應該補充說,account_type每月指的是每月的account_types夾具:這就是困擾我的東西。我有他們幾乎完全相同的方式設置和account_type夾具按預期工作,而credit_card不是。 – Koby 2010-10-08 12:38:54

+0

我繼續前進,嘗試了這一點,它的工作,但我的印象是,你沒有想到硬件編碼固定裝置的ID值,做了這種改變,或者這只是一個例外,而不是規則? – Koby 2010-10-10 01:19:26

0

這還不算一個很好的解決方案,但你可以通過散列與Fixtures.identify燈具的名稱得到一致的ID。

beekin: 
    name: Beekin 
    website: "http://www.beekin.com" 
    hometown_city: Nashville 
    hometown_state: TN 
    subdomain: beekin 
    account_type: monthly 
    account_type_name: "MONTHLY" 
    account_status: "ACTIVE" 
    credit_card_id: <%= Fixtures.identify(:card_one) %> 
    next_payment_date: <%= Date.today %> 

查看http://ar.rubyonrails.org/classes/Fixtures.html#M000009瞭解更多詳情。

(偷偷的,我覺得這是Rails的是如何實現跨越文件「原名」引用。)

相關問題