ruby paperclip到s3错误

时间:2011-05-27 21:40:55

标签: ruby amazon-s3 paperclip

我正在尝试使用带有heroku和s3的回形针,但我有很多可以与照片相关联的表格,我们将使用:例如。 我试图将评论中的照片分开并单独上传,但由于我是红宝石的新手,我觉得我失败了。 我已经安装并捆绑了'aws-s3'宝石。

这是我得到的错误:

LoadError in ReviewsController#create

no such file to load -- aws/s3 (You may need to install the aws-s3 gem)
Rails.root: C:/www/devise

Application Trace | Framework Trace | Full Trace
app/controllers/reviews_controller.rb:56:in `new'
app/controllers/reviews_controller.rb:56:in `block in create'
app/controllers/reviews_controller.rb:54:in `create'
app/controllers/redirect_back.rb:23:in `store_location'
This error occurred while loading the following files:
   aws/s3

照片型号:

class Photo < ActiveRecord::Base
        belongs_to :user
        belongs_to :shop
        belongs_to :baristum
        belongs_to :review

      #paperclip
      has_attached_file :photo,
           :styles => {
           :thumb=> "100x100#",
           :small  => "400x400>",
           :original => "800x800" },
         :storage => :s3,
         :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
         :path => "/:style/:id/:filename"

    end

照片架构:

t.string   "file_name"
    t.string   "content_type"
    t.integer  "file_size"
    t.integer  "user_id"
    t.integer  "barista_id"
    t.integer  "review_id"
    t.integer  "shop_id"
    t.datetime "created_at"
    t.datetime "updated_at"

审核控制器:

def create
    #add the current user to the review hash, from the session var.
    params[:review][:user_id] = current_user.id

    #move the photo to another var, so I can remove it from the review insert
    @photoUpload = params[:review][:photo]
    params[:review].delete("photo")

    @review = Review.new(params[:review])

    respond_to do |format|
      if @review.save
        @photo = Photo.new(:photo => @photoUpload, :review_id => @review.id)
        @photo.save

        format.html { redirect_to(@review, :notice => 'Review was successfully created.') }
        format.xml  { render :xml => @review, :status => :created, :location => @review }
      else
        @shopList = Shop.find(:all)
        format.html { render :action => "new" }
        format.xml  { render :xml => @review.errors, :status => :unprocessable_entity }
      end
    end
  end

的Gemfile

source 'http://rubygems.org'

gem 'pg'
gem 'rake', '~> 0.8.7'
gem 'rails', '3.0.5'
#gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'devise', :git => 'git://github.com/plataformatec/devise', :branch => 'master'
gem 'omniauth', '0.2.0'
gem 'paperclip'
#gem 'RMagick'
gem "simple_form", "~> 1.2.2"
gem 'twitter_oauth', '0.4.3'
gem "rest-client", "1.6.1", :require => "restclient"
gem "sluggable"
gem 'gmaps4rails'
gem 'exception_notification', :require => 'exception_notifier'
gem 'yaml_db'
#gem 'mysql'
gem 'aws-s3'


#gem 'carrierwave'
#gem 'fog' #amazon s3
#gem 'nokogiri'

group :development, :test do
 gem 'rspec-rails'
 gem 'fixjour'
end

3 个答案:

答案 0 :(得分:1)

当您在gem文件中包含'aws-s3'gem时,请记住添加require语句。

gem 'aws-s3', :require => 'aws/s3'

答案 1 :(得分:1)

当前版本的Paperclip使用aws-sdk gem,而不是aws-s3 gem。

尝试运行该gem的最新版本,并结合最新版本的Paperclip,它支持您的Rails堆栈(Paperclip 2.x for Rails 2.3,或Paperclip 3.x for Rails 3 +)。

答案 2 :(得分:0)

看起来您需要在照片架构中包含以下字段。

  t.string :file_file_name
  t.string :file_content_type
  t.integer :file_file_size
  t.datetime :file_updated_at

运行此操作将为您生成迁移

  #this convention: rails generate paperclip [model] [attachmentname]
  rails generate paperclip photo file

您必须按照此约定命名的表格列用于回形针:'attachmentname'_file_name,'attachmentname'_content_type等等...您在哪里调用您的照片模型的has_attachment“文件”。