2013-11-22 136 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!