大家:在将它发布到 Stackoverflow 之前,我已经搜索了该错误,因此无需向我指出:groups.google.com/forum/?fromgroups=#!topic/carrierwave/ 这不是同一个问题。
我正在使用 Carrierwave,因此用户可以将文件上传到我的 Rackspace 容器。但是当我从我的站点提交时(在我的本地机器上,仍处于测试模式),我得到一个Fog::Storage::Rackspace::NotFound app/controllers/authors_controller.rb:8:in `update' 错误。我的 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
编辑.html.erb:
<%= f.file_field :pic %>
<%= f.submit "Save Author Info" %>
当我将此代码“上传”/存储到文件时,效果很好。也许 f.submit 不适用于 Carrierwave?如果不是...我在哪里可以找到正确的提交代码?
有什么想法吗?