Search code examples
rubysinatracarrierwaveirbsequel

Carrierwave, Sequel, Sinatra, import throught irb, update


This is a two-level issue, hope the first one solves the second one.

  1. I'd like to be able to save a new object through a script with something like

    @file = File.open("/path/to/image.png")
    @user = User.new(:name => "SomeName", :avatar => @file)
    @user.save
    

    But sadly, it only responds a

    #<User @values={:name =>"SomeName"}>
    

    so I tried:

    @user = User.new(:name => "SomeName", :avatar => "/path/to/image.png")
    

    but I got:

    CarrierWave::FormNotMultipart: CarrierWave::FormNotMultipart
    

    I need to get the script working because I need import several thousand users :S

    It does work PERFECTLY only when a new User and Avatar get posted via the HTML form, but not upon an update, which takes me to...

  2. Once a User exists I cannot change the avatar by simply doing in my controller

    @user.update(params[:user])
    

I guess the problem is that I am not telling carrierwave all that it needs.


Solution

  • So, this is old. But still, hope it helps someone:

    @user.update(params[:user])
    @user.save
    

    RUN SAVE after the update. That's it!