简体   繁体   中英

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.

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

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

RUN SAVE after the update. That's it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM