2012-01-22 10 views
8

मैं दो अलग-अलग अनुलग्नक फ़ील्ड जोड़ने की कोशिश कर रहा हूं। माइग्रेशन गीलेर में असफल रहा है, मैं इसे बंडलर या बिना इस्तेमाल कर चलाता हूं। (बंडल निष्पादन रेक डीबी: माइग्रेट या बस रेक डीबी: माइग्रेट)।डीबी क्यों है: जब मैं पेपरक्लिप के लिए अनुलग्नक फ़ील्ड जोड़ने की कोशिश करता हूं तो माइग्रेट विफल हो जाता है?

== AddDiagramToQuestion: migrating =========================================== 
-- change_table(:questions) 
rake aborted! 
An error has occurred, this and all later migrations canceled: 

undefined method `has_attached_file' for #<ActiveRecord::ConnectionAdapters::Table:0x0000012b003b20> 
/Users/kboon/Documents/workspace/quiztaker/db/migrate/20111213182927_add_diagram_to_question.rb:6:in `block in up' 
/Users/kboon/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:244:in `change_table' 

प्रवास इस तरह दिखता है:

class AddDiagramToAnswer < ActiveRecord::Migration 
    def self.up 
    change_table :answers do |t| 
     t.has_attached_file :diagram 
    end 
    end 

    def self.down 
    drop_attached_file :answers, :diagram 
    end 
end 

मॉडल भी पेपर क्लिप से जोड़ा तरीकों का संदर्भ और एप्लिकेशन को सभी पर ठीक चलाता है इसलिए इसकी नहीं है कि पेपर क्लिप स्थापित नहीं है। मैंने माइग्रेशन में 'पेपरक्लिप' जोड़ने की भी कोशिश की है, लेकिन इससे कोई मदद नहीं मिली।

+4

आपके 'जेमफाइल' में पेपरक्लिप मणि है? – davidb

+0

हां, मुझे स्पष्ट रूप से यह कहना चाहिए था। has_attached_file मेरे मॉडल में भी ठीक काम करता है –

+0

पेपरक्लिप का कौन सा संस्करण आप उपयोग कर रहे हैं? –

उत्तर

10

माइग्रेशन जो मेरे लिए बनाया गया था अब t.has_attached_file शब्दावली का उपयोग नहीं करता है, यह वास्तव में कॉलम को स्पष्ट रूप से जोड़ता है। माइग्रेशन चल रहा है के द्वारा बनाई गई होगी:

rails generate paperclip Answer diagram 

उदाहरण here चेक बाहर।

+0

यह वही है जो मैंने किया है, भले ही दस्तावेज़ अभी भी has_attached_file विधि का उपयोग करता है। –

2

यह मेरे लिए काम किया

def change 
    create_table :some_table do |t| 
    t.attachment :avatar 
    t.timestamps 
    end 
end 
0

प्रवासन फ़ाइल (answer.rb अपने अनुप्रयोग में तरह

class AddDiagramToAnswer < ActiveRecord::Migration 
    def self.up 
    **add_attachment** :answers, :diagram 
    end 

    def self.down 
    **remove_attachment** :answers, :diagram 
    end 
end 

या

class AddDiagramToAnswer < ActiveRecord::Migration 
    def change 
    create_table :users do |t| 
     t.**attachment** :avatar 
    end 
    end 
end 

has_attached_file model.rb में प्रयोग किया जाता है देखने के लिए किया जाना चाहिए)

रेल के साथ 5