Dan Dan Dan
Dan Dan Dan

Reputation: 5

ruby paperclip to s3 error

I'm trying to use paperclip with heroku and s3, but I have many tables that can be associated with photos, we'll use :review for example. I'm trying to seperate the photo from the review and upload that seperately, but since I'm new to ruby, I think I'm failing miserably. I have the 'aws-s3' gem installed and bundled.

This is the error I'm getting:

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

photo Model:

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

photo schema:

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"

review Controller:

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

Upvotes: 0

Views: 971

Answers (3)

brookr
brookr

Reputation: 1515

Current versions of Paperclip use the aws-sdk gem, rather than the aws-s3 gem.

Try running the latest version of that gem, combined with the latest version of Paperclip which supports your Rails stack (Paperclip 2.x for Rails 2.3, or Paperclip 3.x for Rails 3+).

Upvotes: 1

fedesoria
fedesoria

Reputation: 11

When you include in your gem file the 'aws-s3' gem remember to add the require statement.

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

Upvotes: 1

winfred
winfred

Reputation: 81

Looks like you need to have the following fields in your photos schema.

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

running this will generate a migration for you to do just that

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

You have to have the table columns named following this convention for paperclip to pick them up: 'attachmentname'_file_name, 'attachmentname'_content_type, etc... Where you're calling your Photo model's has_attachment "file".

Upvotes: 0

Related Questions