Elasticsearch Tire Carrierwave远程上传

时间:2013-11-22 15:58:24

标签: ruby-on-rails ruby carrierwave tire

我迫切希望Carrierwave能够与Tire(Elasticsearch gem)合作。

我有一个问题模型,它是一个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记录有效,但没有上传......

有人有想法吗?

干杯

2 个答案:

答案 0 :(得分:0)

应该为非活动记录模型as mentioned here显式调用保存回调。

喜欢@ question.store_image!

使用path作为文件名可能不是一个好主意,因为它令人困惑。 例如:@ question.store_path!

答案 1 :(得分:0)

我遇到了类似的问题,并最终使用Dragonfly for Models,它非常好地与非ActiveRecord模型集成。我正在使用elasticsearch-persistence和模型的独立持久层。