Giter Site home page Giter Site logo

mongoid-paperclip's People

Contributors

2pelaezenrique avatar alexandrebini avatar florentmorin avatar flyerhzm avatar imajes avatar jspaper avatar kpopper avatar mbell697 avatar megatux avatar mrrooijen avatar mschulkind avatar mshibuya avatar sdhull avatar tilsammans avatar tzar avatar warlley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongoid-paperclip's Issues

Mongoid::Paperclip removes logger configuration from Paperclip

The Rails project I'm currently working on has tests for Mongoid objects (RSpec model specs) that don't depend on Rails, they make a Mongoid database connection by hand and don't boot Rails. Also, we disabled Mongoid logging by default as the output isn't usually useful

Mongoid::Paperclip overrides the Paperclip.logger method to be this:

module Paperclip
  class << self
    def logger
      if Mongoid::Config.logger.present?
        Mongoid::Config.logger
      else
        Rails.logger
      end
    end
  end
end

Our tests were failing because, without a Mongoid logger, they were trying to access the Rails logger.

The original Paperclip implementation is this:

module Paperclip
  class << self
    def logger #:nodoc:
      @logger ||= options[:logger] || Logger.new(STDOUT)
    end
  end
end

I have now re-monkeypatched Paperclip and use Paperclip.logger = Logger.new(nil) to disable logging.

Is there a way Paperclip::Mongoid could retain both useful defaults for the logger and the ability to configure (override) it?

(Another potential issue I can see is an app that uses Paperclip with both ActiveRecord and Mongoid, in which case all the logs will be sent to the Mongoid logger, which would probably not make sense. I've not dug into the code to see if this could actually happen though.)

uninitialized constant Mongoid::Paperclip

Raising 'uninitialized constant Mongoid::Paperclip' in model:

class Photo
include Mongoid::Document
include Mongoid::Timestamps::Short
include Mongoid::Paperclip

has_mongoid_attached_file :attachment
embedded_in :story, :inverse_of => :photos
end

Rails 4.0.4
Ruby 2.0.0
Relevant gem versions:
mongoid (4.0.0.beta1)
mongoid-paperclip (0.0.9)
paperclip (>= 2.3.6)
aws-sdk (1.3.9)
httparty (> 0.7)
json (
> 1.4)
nokogiri (>= 1.4.4)
uuidtools (~> 2.1)
mongoid-rspec (1.10.0)
mongoid (>= 3.0.1)
rake
rspec (>= 2.14)

Paperclip validation problem on production

I have a Problem when I deploy my application on google cloud I get this error

has contents that are not what they are reported to be

Locally it works fine! I already tried to using the command_path. So I really don't know what I have to do next...

This is my model

has_mongoid_attached_file  :image,
    :styles => { :large => "380x380!" , :medium => "240x240", :small => "120x120!" },
    :storage => :fog,
    :fog_public => true,
    :fog_directory => 'XXXX',
    :path => "images/:id/:style/:basename.:extension",
    :fog_credentials => {  :provider => 'Google',
                           :google_storage_access_key_id => 'XXXXX',
                           :google_storage_secret_access_key => 'XXXXX'}

  validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]

Thank you for your efforts. I hope you guys can help me

Paperclip::AdapterRegistry::NoHandlerError

Paperclip::AdapterRegistry::NoHandlerError - No handler found for

{
    "filename" => "file.torrent",
        "type" => "application/octet-stream",
        "name" => "incident[docs_attributes][0][attachment]",
    "tempfile" => #<Tempfile:/var/folders/3y/z8_qymc95jl1wkgbcr7v4b780000gn/T/RackMultipart20130911-8612-1541x6w>,
        "head" => "Content-Disposition: form-data; name=\"incident[docs_attributes][0][attachment]\"; filename=\"file.torrent\"\r\nContent-Type: application/octet-stream\r\n"
}

Can't upload to S3

After uploading file I get 200 status. New one row created in DB, but only with _id field
No files uploaded to S3

What am I doing wrong?

Gemfile

gem 'rails', '4.0.3'
gem 'mongoid', '~> 4.0.0.beta1', github: 'mongoid/mongoid'
gem 'mongoid-paperclip', :require => 'mongoid_paperclip', :github => 'meskyanichi/mongoid-paperclip', :branch => 'master'
gem 'aws-sdk', '~> 1.34.1'

Model

class Draft
  include Mongoid::Document
  include Mongoid::Paperclip

  has_mongoid_attached_file :draft,
    :path => ':attachment/:id/:style.:extension',
    :storage        => :s3,
    :s3_credentials => File.join(Rails.root, 'config', 'aws.yml'),
    :styles => {
      :small   => ['298x160#', :png]
    }
end

aws.yml

development:
  bucket: site-develop
  access_key_id: MYKEY
  secret_access_key: MYSECRETKEY
  s3_host_name: s3-eu-west-1.amazonaws.com

Including two image files in model causes error

I have a model with two calls to "has_mongoid_attached_file"

Whichever appears first (in the model) causes an error in the view:

ActionView::Template::Error (can't convert nil into Hash):
7: = f.input :background
8: = f.input :logo
app/views/pages/_form.html.haml:8:in block in _app_views_pages__form_html_haml___272641787_101432820' app/views/pages/_form.html.haml:1:in_app_views_pages__form_html_haml___272641787_101432820'
app/views/pages/new.html.haml:3:in _app_views_pages_new_html_haml___754983345_101515850' app/controllers/pages_controller.rb:48:innew'

undefined method `first' for #<ActionDispatch::Http::UploadedFile:0x00000109915b68>

class Item
include Mongoid::Document
field :name, type: String
field :description, type: String

embeds_many :photos, cascade_callbacks: true
accepts_nested_attributes_for :photos
end

class Photo
include Mongoid::Document
include Mongoid::Paperclip

embedded_in :items, :inverse_of => :photos

has_mongoid_attached_file :attachment,
:storage => :s3,
:bucket => APP_CONFIG[:amazon_s3_photos_bucket],
:styles => {
:original => ['1920x1680>', :jpg],
:small => ['100x100#', :jpg],
:medium => ['250x250', :jpg],
:large => ['500x500>', :jpg]
},
:convert_options => { :all => '-background white -flatten +matte' }
end

I'm seeing undefined method `first' for #ActionDispatch::Http::UploadedFile:0x00000109915b68 error when I try to save the Item..

Unable to destroy attachments in embedded documents

First off, thanks to everyone who helped make this gem possible. It's been great to work with, but I just started to notice some issues when working with embedded documents that happen to have paperclip attachments. When I delete the parent object (in this case Slide) then the images still exist on the local filesystem. In order to destroy the attachments is there another step I must perform in this case?

Here's the code that I'm currently using:

class Riff
  include Mongoid::Document
  include Mongoid::Paperclip
  embedded_in :slide
  has_mongoid_attached_file :slide_image,
    :styles => {:original => "800>", :thumb => "180x120#"},
    :path => 'public/system/riffs/:id/:style.:extension',
    :url => '/system/riffs/:id/:style.:extension'
end

Please let me know if there's any other information I should provide, thanks!

undefined method `bson_type' for ActionDispatch::Http::UploadedFile

undefined method `bson_type' for #ActionDispatch::Http::UploadedFile:0x00000106021618

(someone else submitted the same problem at http://stackoverflow.com/questions/22143969/undefined-method-bson-type-for-actiondispatchhttpuploadedfile0x007f9450; also, there is another similar issue here at #34)

Here's my model:

class MediaSnippet < Snippet
    include Mongoid::Paperclip

    has_mongoid_attached_file :attachment,
        path: ':attachment/:id/:style/:basename.:extension',
        storage: :s3,
        url: ':s3_alias_url',
        s3_host_alias: "#{AWS_S3[:bucket]}.s3.amazonaws.com",
        s3_permissions: :private,
        s3_credentials: "#{Rails.root}/config/s3.yml",
        bucket: AWS_S3[:bucket]
        styles: {
          original: ['1920x1680>', :jpg],
          small: ['100x100#',   :jpg],
          medium: ['250x250',    :jpg],
          large: ['500x500>',   :jpg]
        },

    validate proc { attachment.exists? }

end
class Snippet
    include Mongoid::Document
    include Mongoid::Attributes::Dynamic
    include Mongoid::Timestamps

    embedded_in :session
        ...
end
class Session
    include Mongoid::Document
    include Mongoid::Timestamps

    embeds_many :snippets, validate: false, cascade_callbacks: true
end

My specs:

GIT
  remote: git://github.com/meskyanichi/mongoid-paperclip.git
  revision: 18e9d2d50a337f347e01776201a5f36dda2934cb
  specs:
    mongoid-paperclip (0.0.9)
      paperclip (>= 2.3.6)

GIT
  remote: git://github.com/mongoid/mongoid.git
  revision: dba1c17b1dba667e50347ab616aaf6f2e1bee094
  specs:
    mongoid (4.0.0.beta1)
      activemodel (>= 4.0.0)
      moped (~> 2.0.beta6)
      origin (~> 2.1)
      tzinfo (>= 0.3.37)

GIT
  remote: git://github.com/mongoid/moped.git
  revision: e238b4a757d64d980e3137c5b57a37a1729733a9
  specs:
    moped (2.0.0.beta6)
      bson (~> 2.2)
      connection_pool (~> 1.2)
      optionable (~> 0.2.0)

paperclip (4.1.1)
rails (4.0.2)

rake paperclip:refresh failed

Hi there,

I want to refresh my thumbs so i do rake paperclip:refresh CLASS=Store::Product
and this is what i get:

rake aborted!
The operation: #<Moped::Protocol::Query
@Length=133
@request_id=3
@response_to=0
@op_code=2004
@flags=[:slave_ok]
@full_collection_name="creative_tool_ple_bli_ch_development.store.products"
@Skip=0
@limit=0
@selector={"$where"=>"preview_image_file_name IS NOT NULL"}
@fields=nil>
failed with error 16722: "JavaScript execution failed: SyntaxError: Unexpected identifier"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error./usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:382:in block in query' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:587:in[]'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:587:in block (3 levels) in flush' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:586:inmap'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:586:in block (2 levels) in flush' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:150:inensure_connected'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:582:in block in flush' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:597:inlogging'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:581:in flush' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:570:inprocess'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/node.rb:370:in query' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/cursor.rb:138:inblock in load_docs'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/session/context.rb:105:in block in with_node' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/cluster.rb:251:inwith_secondary'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/session/context.rb:104:in with_node' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/cursor.rb:137:inload_docs'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/cursor.rb:25:in each' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/query.rb:76:ineach'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/moped-1.5.0/lib/moped/query.rb:76:in each' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:122:inblock in each'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:619:in selecting' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:121:ineach'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/mongoid-3.1.4/lib/mongoid/contextual.rb:19:in each' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/mongoid-3.1.4/lib/mongoid/criteria.rb:510:inentries'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/mongoid-3.1.4/lib/mongoid/criteria.rb:510:in method_missing' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/paperclip-3.5.1/lib/paperclip/helpers.rb:37:ineach_instance_with_attachment'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/paperclip-3.5.1/lib/tasks/paperclip.rake:66:in block (4 levels) in <top (required)>' /usr/local/rvm/gems/ruby-1.9.3-p429/gems/paperclip-3.5.1/lib/tasks/paperclip.rake:65:ineach'
/usr/local/rvm/gems/ruby-1.9.3-p429/gems/paperclip-3.5.1/lib/tasks/paperclip.rake:65:in block (3 levels) in <top (required)>' /usr/local/rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:ineval'
/usr/local/rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `

'
Tasks: TOP => paperclip:refresh => paperclip:refresh:metadata
(See full trace by running task with --trace)

Can someone help?

Kind regards, patrick

Using parent ids in the embedded document path for an attachment

I want save an attachment in a path such as:

rails_root/parent/:id_parent/child/:id_child/:filename
class Parent
  include Mongoid::Document
  embeds_many :childrens , cascade_callbacks: true
end

class Child
  include Mongoid::Document
  include Mongoid::Paperclip
  embedded_in :parent, inverse_of: :childrens
  has_mongoid_attached_file :photo,
       path: "parent/:id_parent/child/:id/:filename"
end

How can I use :id_parent? Because right now is undefined and it should have parent ids value.

Conflicts with paperclip 2.4.x

Bundler could not find compatible versions for gem "paperclip":
In Gemfile:
mongoid-paperclip depends on
paperclip (~> 2.3.6)

paperclip (2.4.1)

AWS::S3::AccessDenied: Access Denied

Here is my code..

  include Mongoid::Document
  include Mongoid::Paperclip
  has_mongoid_attached_file :attachment,
    :styles => {:medium => "480x480>", 
      :thumb => "100x100>", 
      :slider => "258x193>"},
    :storage => :s3,
    :s3_credentials => YAML.load_file(File.join(Rails.root, 'config', 's3.yml')),
    :bucket => 'photos',
    :path => ":attachment/:id/:style/:basename.:extension",
    :default_url => "/images/missing.png"
# cat config/s3.yml 
access_key_id: AKIAI577OG2NLC3QSKKA
secret_access_key: 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
## On rails console
irb(main):025:0> p = Print.new
=> #<Print _id: 4e1ac8ebf337e10b7f000004, attachment_file_name: nil, attachment_file_size: nil, attachment_content_type: nil, project_id: nil, _type: "Print", attachment_updated_at: nil>
irb(main):026:0> p.attachment = File.open("/home/sandip/Desktop/1.jpg")
=> #<File:/home/sandip/Desktop/1.jpg>
irb(main):027:0> p.save
AWS::S3::AccessDenied: Access Denied

Doesn't handle inheritance

It does not handle cases where the attachment is defined in the base class and you try to attach files to derived models.

Does not support Mongoid::Versioning

In a model like:

class Mockup
  include Mongoid::Document
  include Mongoid::Paperclip
  include Mongoid::Versioning

  has_mongoid_attached_file :screenshot,
    :url => '/system/mockups/:id/:version/:id.:extension',
    :path => ':rails_root/public:url'

  Paperclip.interpolates :version  do |attachment, style|
    attachment.instance.version
  end
end

Attached files are not kept when updating the model, Paperclip throws them away and on top of that the ':version' part of the url remains '1' (<%= image_tag mockup.screenshot %>).

mongoid 3.1.5

Hi, does mongoid-paperclip work with mongoid 3.1.5?

Odd method error 'first'

I'm getting an odd error when trying to create multiple sized images during upload

undefined method `first' for #<ActionDispatch::Http::UploadedFile:0x105993990>

The code is basically the advanced option in the readme:

class Item
  include Mongoid::Document
  field :name
  embeds_many :images

end
class Image
  include Mongoid::Document
  include Mongoid::Paperclip

  embedded_in :item, :inverse_of => :images

  has_mongoid_attached_file :art,
      :path           => ':id/:style.:extension',
      :storage        => :s3,
      :url            => 'https://s3.amazonaws.com/',
      :bucket => 'buket',
      :s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
      :styles => {
           :original => ['1920x1680>', :jpg],
           :small    => ['100x100#',   :jpg],
           :medium   => ['250x250',    :jpg],
           :large    => ['500x500>',   :jpg]
         }
end

Any ideas what I may be doing wrong? Thanks.

uninitialized constant Mongoid::Paperclip

my gem file looks like

gem "mongoid-paperclip", :require => "mongoid_paperclip"

and model

class User
include Mongoid::Document
include Mongoid::Paperclip
has_mongoid_attached_file :image
end

i am getting error like

uninitialized constant Mongoid::Paperclip

i am using rails 3.2.11

Anybody knows what causing this problem

undefined method `logger' for Mongoid::Config:Module

Using
-rails 3.2.6
-mongoid ~> 3.0.3 (currently 3.0.3)
-mongoid-paperclip

I am getting 'undefined method `logger' for Mongoid::Config:Module'

it looks like 'mongoid_paperclip.rb:15' is trying to do this
if Mongoid::Config.logger.present?
Mongoid::Config.logger
else
Rails.logger
end

but as of this fix, it is Mongoid.logger ( https://github.com/mongoid/mongoid/issues/2221 ).

First 3 of FULL TRACE:
mongoid-paperclip (0.0.7) lib/mongoid_paperclip.rb:15:in logger'
paperclip (3.1.4) lib/paperclip/logger.rb:6:inlog'
paperclip (3.1.4) lib/paperclip/instance_methods.rb:29:in `prepare_for_destroy'

Thanks,

cascade_callbacks: true not working

I have a model that looks like the following

    class Program
      include Mongoid::Document
      include Mongoid::Paperclip

      field :title,         type: String
      field :photo_url,     type: String
      embedded_in :company

      has_mongoid_attached_file :photo, { some_attributes }

      # Called from Sidekiq worker
      def import_image(url)
        self.photo_url = url
        self.photo = URI.parse(url)
        self.save!
        p self #=> print the program with the uploaded photo correctly
               #=> also update the program photo_url correctly
      end
    end

and in the controller i call i upload the photo via

    UploadWorker.perform_async('Program', program_id, program_photo_url, company_id)

The upload worker looks like this

    class UploadWorker
      include Sidekiq::Worker

      def perform(klass, id, url, company_id)
        case klass
        when 'Program'
          Company.find(company_id).programs.find(id).import_image(url)
        end
      end
    end
  • The worker is getting called correctly
  • The program is updated in the worker correctly

But printing the company programs after the worker runs... it doesn't print the program correctly, it prints it as if the photo was not fetched from the url. although that the model have the program.photo_url printed correctly ?

One last thing the company defines the embedded programs as following

    embeds_many :programs, cascade_callbacks: true
    accepts_nested_attributes_for :programs

This is how the first print look like ( the one in the import_image)

    #<Program 
        _id: 530b7080f4eec74f81000004,
        title: "eum",
        photo_url: "http://lorempixel.com/400/600",
        photo_file_name: "600",
        photo_content_type: "image/jpeg",
        photo_file_size: 63953,
        photo_updated_at: 2014-02-24 16:17:04 UTC
    >

And this is the print after the worker is done

    #<Program
        _id: 530b7080f4eec74f81000004,
        title: "eum",
        photo_url: "http://lorempixel.com/400/600",
        photo_file_name: nil,
        photo_content_type: nil,
        photo_file_size: nil,
        photo_updated_at: nil
    >

so my guess is that the call backs didn't run correctly
is there a way to force the call backs to run ... manually in the model or the worker ?

URL Friendly Filenames

Has anyone gotten mongoid-paperclip to handle filenames with non-alphanumeric characters?

For example, uploading a file with the filename A1/2/3/.png silently fails. Newer versions of paperclip have a cleanup_filename method which is not present in this version of mongoid-paperclip. I've also tried adding before_post_process which works for paperclip but does not with mongoid-paperclip.

Suggestions? Thanks

Refresh with embedded models

The paperclip refresh &c commands are broken with embedded models, since it attempts to load from the top level:

$ rake RAILS_ENV=staging paperclip:refresh:missing_styles
Regenerating Image -> photo -> [:background, :thumb]
rake aborted!
Access to the collection for Image is not allowed since it is an embedded document, please access a collection from the root document.

Any ideas on the most efficient way to solve this? I'm happy to make a stab at it.

Photo is not recognized by the 'identify' command.

I'm migrating from Active Record to Mongoid, and this paperclip stuff used to work fine.

I've defined this in my mongoid document:

has_mongoid_attached_file :photo,
:styles => {
:thumb => "60x60",
:small => "100x100",
:medium => "300x200",
:large => "600x400"
},
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml",
:path => "#{Rails.env}/merc_:attachment/:id/:style.:extension",
:url => ":s3_alias_url",
:bucket => '%^&*&^'

I have the rmagick gem installed and also have the command_path pointing to where the various imagemagick commands are.

I'm using Unicorn as my webserver, and I have verified that identiy and convert are available by putting this in my view:

<%= which convert %>
<%= echo $PATH %>

But alas, when I try to upload the image I get :

Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the 'identify' command.
Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the 'identify' command.
Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the 'identify' command.
Photo /tmp/qdoba20121005-27609-1m3kq9c.jpg is not recognized by the 'identify' command.

seemingly one for every one of the styles I have defined.

Help!

Multiple attachments is broken

Hi, I can't get this to function properly with multiple attachments per model. For some reason the mongoid fields don't seem to get setup for the second attachment.

Class definition contains:

has_attached_file :front
has_attached_file :rear

Error

NoMethodError: undefined method `rear_file_name' for #
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/mongoid-2.0.0.beta.20/lib/mongoid/attributes.rb:23:in `method_missing'
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/paperclip-2.3.8/lib/paperclip/attachment.rb:262:in `instance_read'
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/paperclip-2.3.8/lib/paperclip/attachment.rb:172:in `original_filename'
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/paperclip-2.3.8/lib/paperclip/attachment.rb:242:in `file?'
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/paperclip-2.3.8/lib/paperclip/attachment.rb:330:in `queue_existing_for_delete'
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/paperclip-2.3.8/lib/paperclip.rb:370:in `block in destroy_attached_files'
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/paperclip-2.3.8/lib/paperclip.rb:356:in `block in each_attachment'
        from /Users/gdunne/.rvm/gems/ruby-1.9.2-p0@corp/gems/paperclip-2.3.8/lib/paperclip.rb:355:in `each'

$where compile error

Getting '$where compile error' while running rake paperclip:refresh:missing_styles

Everything gets /assets/original/missing.png

This is in my models file:

has_mongoid_attached_file :asset,
    :styles => { :small    => ['36x36#', :jpg],
                 :medium   => ['72x72#', :jpg],
                 :large    => ['115x115#', :jpg] },
    :url => '/:class/:id/:style.:extension',
    :path => ':rails_root/public/uploads/:id_partition/:style.:extension',
    :processors => lambda { |a| a.video? ? [ :video_thumbnail ] : [ :thumbnail ] }

This is my processor:

module Paperclip
  class VideoThumbnail < Processor

    attr_accessor :time_offset, :geometry, :whiny

    def initialize(file, options = {}, attachment = nil)
      super
      @time_offset = options[:time_offset] || '-4'
      unless options[:geometry].nil? || (@geometry = Geometry.parse(options[:geometry])).nil?
        @geometry.width = (@geometry.width / 2.0).floor * 2.0
        @geometry.height = (@geometry.height / 2.0).floor * 2.0
        @geometry.modifier = ''
      end
      @whiny = options[:whiny].nil? ? true : options[:whiny]
      @basename = File.basename(file.path, File.extname(file.path))
    end

    def make
      dst = Tempfile.new([ @basename, 'jpg' ].compact.join("."))
      dst.binmode

      cmd = %Q[-itsoffset #{time_offset} -i "#{File.expand_path(file.path)}" -y -vcodec mjpeg -vframes 1 -an -f rawvideo ]
      cmd << "-s #{geometry.to_s} " unless geometry.nil?
      cmd << %Q["#{File.expand_path(dst.path)}"]

      begin
        success = Paperclip.run('ffmpeg', cmd)
      rescue PaperclipCommandLineError
        raise PaperclipError, "There was an error processing the thumbnail for #{@basename}" if whiny
      end
      dst
    end
  end
end

This is the output from rails when I upload a file:

Started POST "/recordings" for 192.168.0.2 at 2011-11-20 21:27:39 +0000
  Processing by RecordingsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"xVX9V3e6bfXhfDLfjSKxtP9S3mxOFZzCyqeruJ2e/3c=", "recording"=>{"start_date(1i)"=>"2011", "start_date(2i)"=>"11", "start_date(3i)"=>"20", "start_date(4i)"=>"21", "start_date(5i)"=>"27", "end_date(1i)"=>"2011", "end_date(2i)"=>"11", "end_date(3i)"=>"20", "end_date(4i)"=>"21", "end_date(5i)"=>"27", "flagged"=>"0", "asset"=>#<ActionDispatch::Http::UploadedFile:0x00000004ed9e88 @original_filename="20111824_Go_KeithRarick.mp4", @content_type="video/mp4", @headers="Content-Disposition: form-data; name=\"recording[asset]\"; filename=\"20111824_Go_KeithRarick.mp4\"\r\nContent-Type: video/mp4\r\n", @tempfile=#<File:/tmp/RackMultipart20111120-6908-1dg76rt>>, "motion"=>"", "motion_width"=>"", "motion_height"=>"", "motion_xcoord"=>"", "motion_ycoord"=>"", "motion_labels"=>"", "motion_noise"=>""}, "commit"=>"Create Recording"}
Command :: ffmpeg -itsoffset -4 -i "/tmp/stream20111120-6908-2m3d53.mp4" -y -vcodec mjpeg -vframes 1 -an -f rawvideo -s 36x36 "/tmp/stream20111120-6908-2m3d53.jpg20111120-6908-192gp5v"
Command :: ffmpeg -itsoffset -4 -i "/tmp/stream20111120-6908-2m3d53.mp4" -y -vcodec mjpeg -vframes 1 -an -f rawvideo -s 72x72 "/tmp/stream20111120-6908-2m3d53.jpg20111120-6908-13hlx8y"
Command :: ffmpeg -itsoffset -4 -i "/tmp/stream20111120-6908-2m3d53.mp4" -y -vcodec mjpeg -vframes 1 -an -f rawvideo -s 114x114 "/tmp/stream20111120-6908-2m3d53.jpg20111120-6908-yq9org"
MONGODB xanview2_development['system.namespaces'].find({})
[paperclip] Saving attachments.
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/original.mp4
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/small.jpg
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/medium.jpg
[paperclip] saving /root/xanview2/public/uploads/4ec9/70d0/e0ed/181a/fc00/0002/large.jpg

However when I try to access any of the "styles", I get this:

ruby-1.9.3-p0 :027 > Recording.all[0].asset
 => /assets/original/missing.png 
ruby-1.9.3-p0 :028 > Recording.all[0].asset.styles
 => {:small=>#<Paperclip::Style:0x000000058b35f8 @name=:small, @attachment=/assets/original/missing.png, @geometry="36x36#", @format=:jpg, @other_args={}>, :medium=>#<Paperclip::Style:0x000000058b2e00 @name=:medium, @attachment=/assets/original/missing.png, @geometry="72x72#", @format=:jpg, @other_args={}>, :large=>#<Paperclip::Style:0x0000000560c098 @name=:large, @attachment=/assets/original/missing.png, @geometry="115x115#", @format=:jpg, @other_args={}>} 

Any ideas?

`@[]' is not allowed as an instance variable name

Hi!

I try to implement this tutorial: http://thewebfellas.com/blog/2010/1/31/paperclip-vs-amazon-s3-european-buckets with Ruby 1.9.2, Rails 3.1.3, Mongoid 2.2.0, mongoid-paperclip 0.0.7, s3 0.3.9

And I get this error:

NameError in PhotosController#create

`@[]' is not allowed as an instance variable name

lib/patches/paperclip.rb:33:in `block in extended'
lib/patches/paperclip.rb:32:in `instance_eval'
lib/patches/paperclip.rb:32:in `extended'

Request

Parameters:

{"utf8"=>"✓",
 "authenticity_token"=>"neUiYqS3PMWismvVWPSnqUV5NLfAiurkd2x+nslOOAY=",
 "photo"=>{"name"=>"sfs",
 "description"=>"sdd",
 "image"=>#<ActionDispatch::Http::UploadedFile:0x007fe51f274708 @original_filename="IMG_2827new12.jpg",
 @content_type="image/jpeg",
 @headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"IMG_2827new12.jpg\"\r\nContent-Type: image/jpeg\r\n",
 @tempfile=#<File:/var/folders/q8/1cs1q0550x96dq1w1z81f8m40000gn/T/RackMultipart20111128-86583-m3qq5v>>},
 "commit"=>"Создать Photo",
 "locale"=>"ru"}

My /lib/patches/paperclip.rb is https://gist.github.com/1399954

What could it be?

Custom FTP server support

Hello,

I would like to use my own FTP server which is in my country to keep assets of my application because Amazon S3's response time is too long for me.

But I'm unable to find any gems supporting custom FTP with Mongoid.

Would you mind to add this feature to mongoid-paperclip?

destroy or destroy all on embedded documents doesnt destroy all object.

destroy or destroy all on embedded documents doesnt destroy all object.

person.rb

class Person
embeds_many :pictures, :cascading_callback => true
end

picture.rb

class Picture
embedded_in Person

has_mongoid_attached_file :picture
end

in PersonsController

def delete_pictures

if @person.pictures.present?
@person.pictures.destroy_all
end

end

If beforehand the person database have pictures, this WON'T WORK Properly, somehow. Destroy doesnt delete all of my picture objects.

Even with

@person.pictures.each do |p|
p.destroy
end

Doesnt do the trick.

My own hack is to use this:

Controller
while @person.pictures.present?

@person.pictures.destroy_all doesnt work either, coz after that the pictures array is empty, when on next reload not.

@person.pictures.each do |p|
@person.pictures.destroy
end
end

Can somebody explain to me what did i do wrong?

Thanks!

Strange :id in :path — /4f8b/5a82/ef1a/7750/b800/0077/

Hi,

I've just upgraded from Rails 3.1.3 to 3.2.3 and noticed that browser doesn't show images anymore. So I looked to images path and it is /system/photos/images/4fce/1fb6/3ee5/1d01/a800/0006/original/IMG_2842new2.jpg?1338908598 for example. There is no :path declaration in model, so it should use default :rails_root/public/system/:attachment/:id/:style/:filename.

The key thing the images aren't shown is that :id parameter 4fce1fb63ee51d01a8000006 is stored in DB devided by slashes (/) into 4-symbol groups: 4fce/1fb6/3ee5/1d01/a800/0006, but the folder is named as it sould be, 4fce1fb63ee51d01a8000006. That's pretty strange.

I use

mongo (1.6.2) 
mongoid (2.4.10) 
paperclip (3.0.4) 
mongoid-paperclip (0.0.7) 

Refresh missing styles

The paperclip gem includes a rake task (rake paperclip:refresh:missing_styles) to refresh missing styles after deploying.

However, it fails when using mongoid:
undefined method `find_each' for #Mongoid::Criteria:0x00…

There's some suggested fix here:
thoughtbot/paperclip#1064

Looking for collaborators.

Since I haven't used Mongoid and/or Paperclip for quite a while, I'd like to add one or more collaborators that are still actively using this setup and would like to handle pull requests and issues. Comment below if you're interested.

URI::InvalidURIError: URI must be ascii only "http://xiaoniu-ads.oss-cn-hangzhou.aliyuncs.com/a/pic_paths/57bb/ad83/d44f/2108/cbae/ed45/\u{6cf8}\u{5dde}\u{8d21}.jpg"

environment : rails4.2.5,mongoid-paperclip:0.0.10.
when I destroy a record,it rails with "URI::InvalidURIError: URI must be ascii only "http://xiaoniu-ads.oss-cn-hangzhou.aliyuncs.com/a/pic_paths/57bb/ad83/d44f/2108/cbae/ed45/\u{6cf8}\u{5dde}\u{8d21}.jpg"",exactlly my file name contails Chinese,when change the url with Chinese,than it can get.

what can I do to destroy it? or what can i do to let filename from Chinese(UTF_8) to ASCII ?

Deleting records from embeds_many relation, doesn't destroy record.

When I try to delete an attachment through an 'embeds_many' relation, using the _delete key generated by a form, the attachment is deleted but the record remains with it's paperclip
fields set to nil. How do I delete the record from the relation?

class User
  include Mongoid::Document

  embeds_many :photos, cascade_callbacks => true
  accepts_nested_attributes_for :photos, :allow_destroy => true
end

class Photo
  include Monogoid::Document

  has_mongoid_attached_file :attachment
  embedded_in :shopping_center, :inverse_of => :photos
end

When I submit my form to remove the first attachment here's the request that's generated:

{..., "user"=>{
        "photos_attributes"=>{
           "0"=>{"_destroy"=>"1", "id"=>"4f5e30440cc47d6c5400002d"}, 
           "1"=>{"_destroy"=>"false", "id"=>"4f5e30440cc47d6c5400002e"}
         }
       }, 
...}

However when the request is processed through the controller:

class UsersController < ApplicationController
  def update
    @user.= User.find(params[:id])
    @user.update_attributes(params[:user]

    #rendering code here
   end
end

Paperclip issues the appropriate Deleting attachments messages, but then when I view the model, the record still exists. The underlying file has been removed, and all the paperclip fields on the Photo class have been set to nil.

How do I ensure the record is removed from the relation?

Paperclip matchers are not working

Using the matchers mentioned here: http://rdoc.info/github/thoughtbot/paperclip/master/Paperclip/Shoulda/Matchers, I get this rspec errors:

Failures:

1) Image validations 
 Failure/Error: it { should have_attached_file(:image) }
 NoMethodError:
   undefined method `column_names' for Image:Class
 # ./spec/models/image_spec.rb:11:in `block (3 levels) in <top (required)>'

2) Image validations 
 Failure/Error: less_than(10.megabytes) }
 NoMethodError:
   undefined method `is_image_type?' for #<StringIO:0x0000000592e7f8>
 # ./config/initializers/paperclip.rb:57:in `is_image_type?'
 # ./app/models/image.rb:72:in `post_process_image'
 # ./spec/models/image_spec.rb:17:in `block (3 levels) in <top (required)>'

I'm using:
2.0.0.beta.20
mongoid-paperclip (0.0.2)
paperclip (2.3.8)

Ideas?

undefined method `after_commit'

Rails: 4.0.3
Mongoid: 4.0.0.beta1
mongoid-paperclip: 0.0.8
monoid answer: https://github.com/mongoid/mongoid/issues/3546

Can't upload file with paperclip get, I get an error

NoMethodError (undefined method 'after_commit' for Draft:Class): app/models/draft.rb:5:in '<class:Draft>' app/models/draft.rb:1:in '<top (required)>' app/controllers/drafts_controller.rb:27:in 'create'

`class Draft
include Mongoid::Document
include Mongoid::Paperclip

has_mongoid_attached_file :image,
:path => ':attachment/:id/:style.:extension',
:storage => :s3,
:s3_credentials => File.join(Rails.root, 'config', 'aws.yml'),
:styles => {
:small => ['298x160#', :png]
}
end`

embeds_many and paperclip

I upload a file with the nested_form_for and the params are really stored in the database. The file itself is not stored on the filesystem.

What does not work:

class Video < Product
embeds_many :thumbnails

class Thumbnail
include Mongoid::Paperclip
has_mongoid_attached_file :file
embedded_in :product

What does work:
class Video < Product
has_many :thumbnails

class Thumbnail
include Mongoid::Paperclip
has_mongoid_attached_file :file
belongs_to :product

Can somebody helps me? Because i don't want to store the thumbnails in a own collection.

undefined method `after_commit'

I added this gem for a Rails 4 project that is being migrated from MySQL to MongoDB. However, the model that includes the attachment would refuse to load for some reason:

NoMethodError in CsvUploadsController#index
undefined method `after_commit' for CsvUpload:Class

Extracted source (around line #10):
8 field :created_at, :type => DateTime
9 field :updated_at, :type => DateTime
10 has_mongoid_attached_file :upload
11
12 has_many :csv_rows, :dependent => :destroy
13

Full stack trace:

paperclip (3.5.3) lib/paperclip/has_attached_file.rb:84:in `add_active_record_callbacks'
paperclip (3.5.3) lib/paperclip/has_attached_file.rb:19:in `define'
paperclip (3.5.3) lib/paperclip/has_attached_file.rb:4:in `define_on'
paperclip (3.5.3) lib/paperclip.rb:178:in `has_attached_file'
mongoid-paperclip (0.0.8) lib/mongoid_paperclip.rb:70:in `has_mongoid_attached_file'
app/models/csv_upload.rb:10:in `<class:CsvUpload>'
app/models/csv_upload.rb:1:in `<top (required)>'
activesupport (4.0.1) lib/active_support/dependencies.rb:424:in `load'
activesupport (4.0.1) lib/active_support/dependencies.rb:424:in `block in load_file'
activesupport (4.0.1) lib/active_support/dependencies.rb:616:in `new_constants_in'
activesupport (4.0.1) lib/active_support/dependencies.rb:423:in `load_file'
activesupport (4.0.1) lib/active_support/dependencies.rb:324:in `require_or_load'
activesupport (4.0.1) lib/active_support/dependencies.rb:463:in `load_missing_constant'
activesupport (4.0.1) lib/active_support/dependencies.rb:184:in `const_missing'
activesupport (4.0.1) lib/active_support/inflector/methods.rb:226:in `const_get'
activesupport (4.0.1) lib/active_support/inflector/methods.rb:226:in `block in constantize'
activesupport (4.0.1) lib/active_support/inflector/methods.rb:224:in `each'
activesupport (4.0.1) lib/active_support/inflector/methods.rb:224:in `inject'
activesupport (4.0.1) lib/active_support/inflector/methods.rb:224:in `constantize'
activesupport (4.0.1) lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
cancan (1.6.10) lib/cancan/controller_resource.rb:147:in `resource_class'
cancan (1.6.10) lib/cancan/controller_resource.rb:187:in `resource_base'
cancan (1.6.10) lib/cancan/controller_resource.rb:77:in `load_collection?'
cancan (1.6.10) lib/cancan/controller_resource.rb:33:in `load_resource'
cancan (1.6.10) lib/cancan/controller_resource.rb:25:in `load_and_authorize_resource'
cancan (1.6.10) lib/cancan/controller_resource.rb:10:in `block in add_before_filter'
activesupport (4.0.1) lib/active_support/callbacks.rb:397:in `_run__921612280562089967__process_action__callbacks'
activesupport (4.0.1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.1) lib/abstract_controller/callbacks.rb:17:in `process_action'
actionpack (4.0.1) lib/action_controller/metal/rescue.rb:29:in `process_action'
actionpack (4.0.1) lib/action_controller/metal/instrumentation.rb:31:in `block in process_action'
activesupport (4.0.1) lib/active_support/notifications.rb:159:in `block in instrument'
activesupport (4.0.1) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.0.1) lib/active_support/notifications.rb:159:in `instrument'
actionpack (4.0.1) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
actionpack (4.0.1) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'
actionpack (4.0.1) lib/abstract_controller/base.rb:136:in `process'
actionpack (4.0.1) lib/abstract_controller/rendering.rb:44:in `process'
actionpack (4.0.1) lib/action_controller/metal.rb:195:in `dispatch'
actionpack (4.0.1) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
actionpack (4.0.1) lib/action_controller/metal.rb:231:in `block in action'
actionpack (4.0.1) lib/action_dispatch/routing/route_set.rb:80:in `call'
actionpack (4.0.1) lib/action_dispatch/routing/route_set.rb:80:in `dispatch'
actionpack (4.0.1) lib/action_dispatch/routing/route_set.rb:48:in `call'
actionpack (4.0.1) lib/action_dispatch/journey/router.rb:71:in `block in call'
actionpack (4.0.1) lib/action_dispatch/journey/router.rb:59:in `each'
actionpack (4.0.1) lib/action_dispatch/journey/router.rb:59:in `call'
actionpack (4.0.1) lib/action_dispatch/routing/route_set.rb:680:in `call'
rack-livereload (0.3.15) lib/rack/livereload.rb:23:in `_call'
rack-livereload (0.3.15) lib/rack/livereload.rb:14:in `call'
warden (1.2.3) lib/warden/manager.rb:35:in `block in call'
warden (1.2.3) lib/warden/manager.rb:34:in `catch'
warden (1.2.3) lib/warden/manager.rb:34:in `call'
rack (1.5.2) lib/rack/etag.rb:23:in `call'
rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
rack (1.5.2) lib/rack/head.rb:11:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/flash.rb:241:in `call'
rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/cookies.rb:486:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
activesupport (4.0.1) lib/active_support/callbacks.rb:373:in `_run__2054036283427034282__call__callbacks'
activesupport (4.0.1) lib/active_support/callbacks.rb:80:in `run_callbacks'
actionpack (4.0.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/reloader.rb:64:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/remote_ip.rb:76:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.0.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.0.1) lib/rails/rack/logger.rb:20:in `block in call'
activesupport (4.0.1) lib/active_support/tagged_logging.rb:67:in `block in tagged'
activesupport (4.0.1) lib/active_support/tagged_logging.rb:25:in `tagged'
activesupport (4.0.1) lib/active_support/tagged_logging.rb:67:in `tagged'
railties (4.0.1) lib/rails/rack/logger.rb:20:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.5.2) lib/rack/methodoverride.rb:21:in `call'
rack (1.5.2) lib/rack/runtime.rb:17:in `call'
activesupport (4.0.1) lib/active_support/cache/strategy/local_cache.rb:83:in `call'
rack (1.5.2) lib/rack/lock.rb:17:in `call'
actionpack (4.0.1) lib/action_dispatch/middleware/static.rb:64:in `call'
rack (1.5.2) lib/rack/sendfile.rb:112:in `call'
railties (4.0.1) lib/rails/engine.rb:511:in `call'
railties (4.0.1) lib/rails/application.rb:97:in `call'
rack (1.5.2) lib/rack/content_length.rb:14:in `call'
thin (1.6.1) lib/thin/connection.rb:82:in `block in pre_process'
thin (1.6.1) lib/thin/connection.rb:80:in `catch'
thin (1.6.1) lib/thin/connection.rb:80:in `pre_process'
thin (1.6.1) lib/thin/connection.rb:55:in `process'
thin (1.6.1) lib/thin/connection.rb:41:in `receive_data'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run_machine'
eventmachine (1.0.3) lib/eventmachine.rb:187:in `run'
thin (1.6.1) lib/thin/backends/base.rb:73:in `start'
thin (1.6.1) lib/thin/server.rb:162:in `start'
rack (1.5.2) lib/rack/handler/thin.rb:16:in `run'
rack (1.5.2) lib/rack/server.rb:264:in `start'
railties (4.0.1) lib/rails/commands/server.rb:84:in `start'
railties (4.0.1) lib/rails/commands.rb:76:in `block in <top (required)>'
railties (4.0.1) lib/rails/commands.rb:71:in `tap'
railties (4.0.1) lib/rails/commands.rb:71:in `<top (required)>'
script/rails:6:in `require'
script/rails:6:in `<main>'

(Note: Temporarily disabling Devise and CanCan did not help, and all previous references to ActiveRecord have been removed from the config files to the best of my knowledge.)

I looks like there is a new amazon gem

paperclip now requires, aws-sdk -- if you use aws-s3, you get:

LoadError in BlogsController#update

no such file to load -- aws-sdk (You may need to install the aws-sdk gem)
Rails.root: /app

Application Trace | Framework Trace | Full Trace
app/models/blog.rb:40:in `page_tokens='
app/controllers/blogs_controller.rb:56:in `block in update'
app/controllers/blogs_controller.rb:55:in `update'
This error occurred while loading the following files:
aws-sdk

AccessDenied XML document on S3 when trying to access an uploaded photo

Here is my bucket policy on S3:

{
    "Version": "2008-10-17",
    "Statement": [
        {
            "Sid": "AllowPublicRead",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::BUCKET_NAME/avatars/*"
        }
    ]
}

Here is the code in my Profile model to initialize Paperclip:

has_mongoid_attached_file :avatar,
    :styles => { :square => ['50x50#', :jpg], :large => ['225x150#', :jpg] },
    :storage => :"#{Settings.paperclip.storage}",
    :hash_secret => "#{Settings.paperclip.app_secret}",
    :path => ":attachment/:style/:hash.:extension",
    :fog_credentials => {
      :aws_access_key_id => Settings.aws.s3_key,
      :aws_secret_access_key => Settings.aws.s3_secret,
      :provider => 'AWS'
    },
    :fog_directory => Settings.aws.s3_bucket,
    :processors => [:cropper]

If I go into S3, right click on my bucket folder and click Make public, I can access all the uploaded files publically. But if I upload a new file and try to access it via the S3 url, my browser gives me an AccessDenied XML document.

<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>4B8296F8F77491F5</RequestId>
<HostId>
CG96q+LGWcvsIK2YkuaE2wExL8/YTqH1PmjOSFGAqcgaKaTYnOet1QoItGJhW1Oj
</HostId>
</Error>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.