【发布时间】:2012-10-16 20:35:34
【问题描述】:
大家:我在将它发布到 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
控制器 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?如果没有...我在哪里可以找到正确的提交代码?
有什么想法吗?
【问题讨论】:
-
我从未使用过 Rackspace,但您提供的容器名称是否正确?您可能遇到与groups.google.com/forum/?fromgroups=#!topic/carrierwave/… 相同的错误
-
已经看到那个话题,我在上面提到了我的容器名称。所以,不,这不是我遇到的问题。我什至尝试制作一个新容器,使用新 URL 等,但仍然是同样的问题。而且由于容器不识别目录(仅对象),我尝试将目录名称从 def store_dir "#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 结尾弄乱没有运气。
标签: ruby-on-rails-3 file-upload carrierwave rackspace fog