0

我跟隨railscasts使用carrierwave霧與aws s3到T但它似乎沒有工作。CarrierWave無法使用霧 - > ArgumentError(不是一個公認的存儲提供商):應用程序/控制器/ notes_controller.rb:11:在'創建'

的的Gemfile如下:

source 'https://rubygems.org' 
ruby '1.9.3' 
gem 'rails', '3.2.13' 


# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 

gem 'pg' 
gem 'pg_search' 

gem 'devise' 

gem "therubyracer" 
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS 
gem "twitter-bootstrap-rails", :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git' 
gem "simple_form" 
gem 'aws-sdk', '~> 1.8.1.2' 
gem 'activerecord-reputation-system', require: 'reputation_system' 
gem 'bootstrap-will_paginate' 

gem 'carrierwave' 
gem "rmagick" 
gem "fog", "~> 1.3.1" 
gem 'carrierwave-aws' 

配置/初始化/ carrierwave.rb

require 'carrierwave' 

CarrierWave.configure do |config| 
    config.fog_credentials = { 
    provider: "AWS", 
    aws_access_key_id: ENV["xxx"], 
    aws_secret_access_key: ENV["yyy"], 
    region: ENV['ap-southeast-1'] 
    } 

    config.cache_dir = "#{Rails.root}/tmp/uploads" 
    config.fog_directory = ENV["ABC"] 
end 

上傳者:

class ImageUploader < CarrierWave::Uploader::Base 
require 'carrierwave/processing/mime_types' 

    before :store, :remember_cache_id 
    after :store, :delete_tmp_dir 

    # Include RMagick or MiniMagick support: 
    include CarrierWave::RMagick 
    # include CarrierWave::MiniMagick 

    # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility: 
    include Sprockets::Helpers::RailsHelper 
    include Sprockets::Helpers::IsolatedHelper 

    # Choose what kind of storage to use for this uploader: 
    # storage :file 
    storage :fog 

    include CarrierWave::MimeTypes 

    process :set_content_type 
    # Override the directory where uploaded files will be stored. 
    # This is a sensible default for uploaders that are meant to be mounted: 
    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

    version :thumb do 
    process :resize_to_limit => [200, 200] 
    end 

    # store! nil's the cache_id after it finishes so we need to remember it for deletion 
    def remember_cache_id(new_file) 
    @cache_id_was = cache_id 
    end 

    def delete_tmp_dir(new_file) 
    # make sure we don't delete other things accidentally by checking the name pattern 
    if @cache_id_was.present? && @cache_id_was =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/ 
     FileUtils.rm_rf(File.join(root, cache_dir, @cache_id_was)) 
    end 
    end 
end 

控制器:

class NotesController < ApplicationController 
    before_filter :authenticate_user!, only: [:create, :destroy] 
    before_filter :correct_user, only: :destroy 

    def index 
    end 

    def create 
     @note = current_user.notes.build(params[:note]) 
     @notes = Note.paginate(page: params[:page]) 
    if @note.save 
     flash[:success] = "Note uploaded!" 
     redirect_to root_url 
    else 
     flash.now[:error] = "Note failed to upload." 
     render 'static_pages/home' 
    end 
    end 

    def destroy 
     @note.destroy 
     flash[:success] = "Note deleted." 
     redirect_to root_url 
    end 

private 

    def correct_user 
     @note = current_user.notes.find_by_id(params[:id]) 
     redirect_to root_url if @note.nil? 
    end 
end 

我真的不知道,如果問題出在創業板或控制器。即使控制器是基於Michael Hartl的書「Ruby on Rails教程」中的microposts控制器,所以我不知道我出錯的地方。

+0

@AronMak什麼的O/P'CarrierWave ::上傳:: Base.fog_credentials'狀態 – Viren

回答

0

這是霧的一個非常早期的版本。最新的是1.12.1。嘗試在Gemfile

gem "fog", "~> 1.12.1" 
+0

抱歉,但它仍然是行不通的更新使用以下條目的最新版本。我最初遵循CarrierWave gem中給出的文檔,這就是霧是舊版本的原因。 –

相關問題