2015-07-13 19 views
8

Ich habe diesen Fehler: Errno::ENOENT in PicturethingsController#update_profile.Rails aktive Datensatzduplizierung und Sicherungsfehler

No such file or directory - /Users/Baz/rails/myapp/public/uploads/picturething/picture/49/cat.jpg

Ich versuche, die standardpicture aufzeichnen und speichern, das zu @ character.profilepicture zu duplizieren. Ich kann auch nicht @ character.profilepicture in der Datenbank speichern (ich weiß von der Überprüfung nach Eingabe der Rails-Konsole). Hier

ist die säumige Methode:

picturethings_controller.rb:

def update_profile 
    @character = Character.find_by(callsign: params[:callsign]) 
    standardpicture = Picturething.find_by(id: params[:picid]) 
    @character.build_profilepicture 
    @character.profilepicture.save! 
    @character.profilepicture = standardpicture.dup 
    @character.profilepicture.save! 
    @character.profilepicture.picture.recreate_versions! 
    @character.profilepicture.picture = @character.profilepicture.picture.profile 
    respond_to do |format| 
    format.html do 
     redirect_to @character.sociable 
    end 
    format.js 
    end 
end 

character.rb:

has_many :standardpictures, class_name: "Picturething", 
          inverse_of: :character, 
          foreign_key: "character_standard_id", 
          dependent: :destroy 
has_one :profilepicture, class_name: "Picturething", 
          inverse_of: :character, 
          foreign_key: "character_profile_id", 
          dependent: :destroy 

picturething.rb:

mount_uploader :picture, CharacterpicUploader 
+1

Versuchen Sie '@ character.profilepicture.save!' Nach '@ character.build_profilepicture' zu ​​entfernen. – Pavan

+1

Ich fürchte, ich bekomme immer noch den gleichen Fehler. – Bazley

Antwort

6
@character.profilepicture = standardpicture.dup 

Das Problem dabei ist, dass es die Attribute des Active Objekts nur ist das Kopieren, aber es wird das eigentliche Bild auf der Festplatte nicht kopieren, so dass, wenn Sie dann

@character.profilepicture.picture = @character.profilepicture.picture.profile 

tun wirft es einen No such file or directory Fehler. Versuchen Sie, this gem zu verwenden, um Ihnen zu helfen, Ihre CarrierWave-Anhänge zwischen AR-Datensätzen zu kopieren.

+1

Ich stimme mit carrierwave überein, aber hier ist der Link von ruby-toolbox zu [rails file uploads] (https://www.ruby-toolbox.com/categories/rails_file_uploads) – daslicious

Verwandte Themen