gpt4 book ai didi

ruby-on-rails-3 - 使用 Carrierwave 上传到 Rackspace 时出现 Fog::Storage::Rackspace::NotFound 错误

转载 作者:行者123 更新时间:2023-12-02 07:39:15 24 4
gpt4 key购买 nike

每个人:在将此错误发布到 Stackoverflow 之前,我已经搜索过该错误,因此无需向我指出此问题:groups.google.com/forum/?fromgroups=#!topic/carrierwave/这不是同一个问题。

我正在使用 Carrierwave,因此用户可以将文件上传到我的 Rackspace 容器。但是当我从我的站点提交时(在我的本地机器上,仍处于测试模式),我得到一个 Fog::Storage::Rackspace::NotFound app/controllers/authors_controller.rb:8:in “更新”错误。我的 Rackspace 容器称为 kontainer.ofstuff。这是我的代码:

pic_uploader.rb:

class PicUploader < CarrierWave::Uploader::Base

include Rails.application.routes.url_helpers
storage :fog

def store_dir
"#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end

模型作者.rb

class Author < ActiveRecord::Base
attr_accessible :stuff, :profilepic

mount_uploader :pic, PicUploader

def dostuff
end
end

carrierwave.rb 在config/initializers目录下

CarrierWave.configure do |config|

config.storage = :fog
config.fog_credentials = {
:provider => 'Rackspace',
:rackspace_username => 'myusername',
:rackspace_api_key => '98765asecretnumber3'
})
config.fog_directory = 'kontainer.ofstuff'
config.fog_host = 'https://34567secretnumberiiiii.ssl.cf2.rackcdn.com'
end

Controller authors_controller.rb

class AuthorsController < ApplicationController

def update
@author = Author.find(params[:id])
@booklist = Book.where(:author_id => @author.id)
#line 7
if @author.update_attributes(params[:author])
sign_in @author
redirect_to @author
else
render 'profileinfo'
end
end
end

edit.html.erb:

<%= f.file_field :pic %>
<%= f.submit "Save Author Info" %>

当我将此代码“上传”/存储到文件时,效果很好。也许 f.submit 不适用于 Carrierwave?如果不是...我在哪里可以找到正确的提交代码?

知道问题出在哪里吗?

最佳答案

我也遇到了这个错误。通过将此添加到上传的代码来解决:

class MyUploader < CarrierWave::Uploader::Base

....

def remove!
begin
super
rescue Fog::Storage::Rackspace::NotFound
end
end

end

关于ruby-on-rails-3 - 使用 Carrierwave 上传到 Rackspace 时出现 Fog::Storage::Rackspace::NotFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12922980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com