2013-11-22 432 views
1

我拼命地沒有成功使Carrierwave與Tyre(Elasticsearch gem)合作。Elasticsearch輪胎Carrierwave遠程上傳

我有一個問題模型,它是一個ActiveRecord之一,但我用Tire將它遷移到Elasticsearch上。直到它在ActiveRecord上時,一切都很好。但現在不行了。

我想要的是將遠程文件(從Facebook)上傳到S3存儲桶。所有的配置文件是正確的(因爲它是在ActiveRecord的模式工作)

這裏是我的問題型號:

class Question 

    include ActiveModel::MassAssignmentSecurity 
    include ActiveModel::Validations 

    extend CarrierWave::Mount 

    include Tire::Model::Callbacks 
    include Tire::Model::Persistence 

    # set fields for carrierwave uploader 
    mount_uploader :path, QuestionUploader 

    validates_presence_of :question 

    attr_accessible :path 
    attr_accessor :remote_path_url, :remove_path 

    property :difficulty 
    property :question 
    property :path 

end 

然後在我的questions_controller:

class QuestionsController < ApplicationController 

    def create 

     @question = Question.new question: "How are you ?", difficulty: 3 
     @question.remote_path_url = "http://domain.com/file.jpg" 
     @question.save 

     render nothing: true 

    end 

end 

Elasticsearch紀錄的作品,但沒有上傳發生...

有人有想法嗎?

乾杯

回答

0

保存回調後,應明確要求非活動記錄模式,as mentioned here

贊@ question.store_image!

此外,使用路徑作爲文件名可能不是個好主意,因爲它很混亂。 例如:@ question.store_path!