2015-04-15 28 views
1

我正在使用rails版本'2.3.18'的維護項目。 我能夠運行遷移但無法獲取數據。 有一個在DB號seeds.rb文件,但有一個名爲example_data.rb作爲一個文件:如何運行位於rails(版本2.3.18)db文件夾中的文件

module FixtureReplacement 
    attributes_for :category do |c| 
    c.name = "General" 
    c.desc = "general" 
    end 
    attributes_for :price, :from => :equity do |a| 
    a.etype = "dollars" 
    a.exchange = '60' 
    end 
.......................... 
................. 
end 

我認爲這是該項目的種子文件。我試着運行

rake db:example_data(recollecting rake db:seed),但沒有運氣。

請幫助我,如何運行此文件。

+0

在所有項目文件中進行研究並查找'FixtureReplacement',您可能會發現一個調用此模塊的特定文件,並可能提示如何運行它。 – MrYoshiji

回答

1

不幸的是,這不是一個種子文件,而是替代Rails內置的固件,名爲FixtureReplacement,這個替代品可用於您的測試環境。這與FabricationFactoryGirl類似。

該文件實際上並未定義任何預設數據,而是爲您提供了一種更清晰的方式來創建具有預設默認值的記錄。您將無法簡單地運行該文件,但可以編寫包含您的Rails環境的腳本幷包含FixtureReplacement。從那裏,你可以通過命令生成的數據,如圖FixtureReplacementdocumentation:老實說,雖然

# Require Rails env on this line 
include FixtureReplacement 
new_category # Uses defaults 
new_category(name: "Something", desc: "something") 
new_price # Uses defaults 
# and so on 

,它可能是明智的只是腳本的東西從頭開始。

+0

非常感謝@faraz。特別是[文檔](http://replacefixtures.rubyforge.org/)幫了我很多。 – venkat

+1

祝你好運!你需要它...遺留代碼總是很痛苦。 ;) – fny

相關問題