1

I'm desperately don't success to make Carrierwave working with Tire (Elasticsearch gem).

I have a Question model which was an ActiveRecord one, but I migrated it on Elasticsearch with Tire. Until it was on ActiveRecord everything was working great. But not anymore.

What I want is to upload a remote file (from Facebook) to a S3 bucket. All config files are correct (as it was working under ActiveRecord model)

Here is my Question model:

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

And then in my 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 record works, but no upload happens...

Someone has an idea ?

Cheers

Gozup
  • 1,005
  • 2
  • 10
  • 20

2 Answers2

0

After save callback should be explicitly called for non active record models, as mentioned here.

Like @question.store_image!

Also it may not be good idea to use path as file name, as it is confusing. For example: @question.store_path!

Vijendra
  • 338
  • 3
  • 11
0

I had a similar problem and ended up using Dragonfly for Models which integrated very well with a non-ActiveRecord model. I am using elasticsearch-persistence with a standalone persistence layer for models.

jogaco
  • 712
  • 8
  • 25