carrierwaveuploader / carrierwave-mongoid Goto Github PK
View Code? Open in Web Editor NEWMongoid support for CarrierWave
License: MIT License
Mongoid support for CarrierWave
License: MIT License
Hi,
jimmy-bandits-MacBook-Pro:vsync jimmy$ ruby -v
jruby 1.6.4 (ruby-1.8.7-p330) (2011-08-23 17ea768) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [darwin-x86_64-java]
jimmy-bandits-MacBook-Pro:vsync jimmy$ gem list
*** LOCAL GEMS ***
activemodel (3.0.10)
activerecord (3.0.10)
activerecord-jdbc-adapter (1.1.3)
activesupport (3.1.0, 3.0.10)
arel (2.0.10)
bcrypt-ruby (3.0.0 java)
bouncy-castle-java (1.5.0146.1)
bson (1.3.1 jruby)
builder (3.0.0, 2.1.2)
carrierwave (0.5.7)
i18n (0.6.0, 0.5.0)
jruby-launcher (1.0.8 java)
jruby-openssl (0.7.4)
mini_magick (3.3)
mongo (1.3.1)
mongoid (2.2.0)
multi_json (1.0.3)
rake (0.8.7)
subexec (0.1.0)
tzinfo (0.3.29)
wirble (0.1.3)
jimmy-bandits-MacBook-Pro:vsync jimmy$ gem install carrierwave-mongoid
ERROR: While executing gem ... (ArgumentError)
undefined class/module YAML::Syck::DefaultKey
jimmy-bandits-MacBook-Pro:vsync jimmy$
$ gem install carrierwave-mongoid
ERROR: While executing gem ... (NameError)
uninitialized constant Syck::Syck
Please push a new gem baked with RubyGems > 1.8.6. Some links:
fnando/i18n-js#45
rubygems/rubygems#121
Thank you.
Hi!
for the version 0.1.1 I have a question:
I used to manipulate the db-field ..._filename (like upload_filename) manually. The readme doesn't state were it went, but I guess it's now equally named to the uploader-method, right?
Can I still manipulate it (read it, update it) without having to use the lower level methods like update_attributes?
E.g. a method that sanitizes the filename for output used to work on upload_filename now doesn't work on upload anymore:
def sanitized_filename
if upload
upload[%r|\Ahttps?://|] ?
upload[%r|^http://([a-zA-Z0-9.\-]+)|, 1] :
upload
end
end
gives an error.
--Frank
I have uploaded a file via carrierwave-mongoid and I can't fetch it nor from within my Rails app nor with mongofiles. Is carrierwave-mongoid uploading a corrupted file?
$ mongofiles -d atlas_development list
connected to: 127.0.0.1
uploads/alfa_logo2.jpg 68125
$ mongofiles get uploads/alfa_logo2.jpg
connected to: 127.0.0.1
assertion: 13325 couldn't open file: uploads/alfa_logo2.jpg
I can upload and download files with mongofiles.
My Gemfile:
gem 'mongoid'
gem 'carrierwave'
gem "carrierwave-mongoid",
git: "git://github.com/jnicklas/carrierwave-mongoid.git",
branch: "mongoid-3.0"
Carrierwave configuration:
CarrierWave.configure do |config|
config.storage = :grid_fs
config.root = Rails.root.join('tmp')
config.cache_dir = "uploads"
config.grid_fs_access_url = "/system/images"
end
I'm using mongoid-3.0. The uploaded picture cannot be viewed. I tried to use Mongoid::GridFS to load the picture with data method. It returns empty string.
Initializer:
require 'carrierwave/mongoid'
CarrierWave.configure do |config|
config.grid_fs_database = 'bga'
config.grid_fs_port = 27017
config.grid_fs_host = '127.0.0.1'
config.grid_fs_username = 'asdasd'
config.grid_fs_password = 'asda'
config.storage = :grid_fs
config.root = Rails.root.join('tmp')
config.cache_dir = "uploads"
end
Error:
config/initializers/carrier_wave.rb:4:in `block in <top (required)>': undefined method `grid_fs_database=' for CarrierWave::Uploader::Base:Class (NoMethodError)
from /Users/ernest.bursa/.rvm/gems/ruby-1.9.3-p194/gems/carrierwave-0.6.2/lib/carrierwave/uploader/configuration.rb:97:in `configure'
Gemfile
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
As mentioned here: carrierwaveuploader/carrierwave#327
...we have changes in Carrierwave 0.5.5 that aren't in this new carrierwave-mongoid gem because I didn't realize it existed!
I have a mounter attached to an embedded model, which works fine when creating a new embedded document. However, when I try to update the document I run into:
undefined method `find' for #ProfileImage:0x0000010c0080e0
The issue originates in
carrierwave-mongoid (0.1.3) lib/carrierwave/mongoid.rb:46:in `find_previous_model_for_image'
It seems there is only support for embeds_many, not embeds_one, such as in my case. I.e.:
Model->(embeds_one)->Model->mounter
Or am I doing things wrong?
-ra
Hi Guys
We facing here a strange behavior. The following test works only if I reload the project. Without reloading it does not store changes in the database instantly and the controller that reads the project while visiting the old data without the image. Is this a bug or a false implementation?
describe 'show project' do
before { @project = create(:project) }
it 'displays project details' do
@project.parent = create(:project)
@project.image = File.open(Rails.root.join("spec","support","files","1x1.png"))
@project.save
@project.reload # Drity hack otherwise changes doesn't hit the database
visit project_path(@project)
page.should have_selector("img[src$='#{project_image_path(@project, '1x1.png')}']")
end
We use
carrierwave (0.8.0)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
carrierwave-mongoid (0.5.0)
carrierwave (~> 0.8.0)
mongoid (~> 3.0)
mongoid-grid_fs (~> 1.3)
Uploader:
require 'carrierwave/processing/mime_types'
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
include CarrierWave::MiniMagick
storage :grid_fs
process :set_content_type
process convert: 'png'
version :small do
process resize_to_fit: [125, 125]
end
def extension_white_list
%w(jpg jpeg gif png)
end
def store_dir
"#{model.id}/#{mounted_as.to_s.pluralize}"
end
def grid_fs_access_url
"/#{I18n.locale}/#{model.class.to_s.tableize}"
end
def default_url
'placeholder.jpg'
end
end
and the project...
class Project
include Extensions::ApplicationModel
include Extensions::SearchConcern
include Mongoid::Tree
include Mongoid::Tree::Traversal
scope :opened, where(state: 'open')
scope :closed, where(state: 'closed')
scope :recents, lambda { |limit = 5| desc(:created_at).limit(limit) }
store_in collection: 'projects'
field :name, type: String
field :description, type: String
field :number, type: String
field :started_at, type: Date
mount_uploader :image, ImageUploader
belongs_to :user
...
end
I'm not too familiar with the carrierwave-mongoid code base, but is there any plans to add support for Mongoid 3? I currently have Mongoid 2.1 working.
There seems to be a problem with the image rendering process on the application server, the image is partially rendered sometimes and sometimes it isn't rendered at all
We are using carrierwave-mongoid 0.5, mongoid 3.0.9 and carrierwave 0.8
This issue occurred when we added new gems to our application and we had to stop using version 3 of the carrierwave-mongoid as it is no longer available
Please find attached 3 attempts to upload the same image
Could you please let me know if any similar issues have been reported?
I have a simple SwfUploader (storage :file) mounted to an Item model as :swf field. I was using item.swf_url to create SWF links.
After update to carrierwave-mongoid 0.3.0, that method returns nil and all links are now broken. What can I do to fix that?
Thanks
I have a simple Photo model
class Photo
include Mongoid::Document
mount_uploader :photo_image, PhotoUploader
belongs_to :attachable, polymorphic: true
end
My photos upload and save fine, but when I call as_json
I get an undefined method [] for nil class.
1.9.3p362 :009 > Photo.first.as_json
NoMethodError: undefined method `[]' for nil:NilClass
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:67:in `block in serializable_hash'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:66:in `each'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:66:in `serializable_hash'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/activemodel-3.2.11/lib/active_model/serializers/json.rb:96:in `as_json'
from (irb):9
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
from /Users/jeremy/.rvm/gems/ruby-1.9.3-p362@tabeso/gems/railties-3.2.11/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Now, if I pass an empty hash, it works.
1.9.3p362 :010 > Photo.first.as_json({})
=> {"_id"=>"50f5d85fd86367cc3c000001", "attachable_field"=>nil, "attachable_id"=>"50f49d74d863677939000134", "attachable_type"=>"Event", "photo_image"=>{"url"=>"", :thumb=>{"url"=>""}}, "primary"=>true, "url"=>nil}
I think just changing the default argument in this method from nil to {} should fix it.
https://github.com/jnicklas/carrierwave-mongoid/blob/master/lib/carrierwave/mongoid.rb#L64
Testing with Mongoid 3.1
The record is persisted, here are the steps:
draft.cover_portrait #=> http://localhost:3000/uploads/version_revision/cover_portrait/51091383421aa9c1d9000004/9ec62177c8e846cb8974f2b49e3df089.jpg
draft.cover_portrait.present? #=> false
draft.cover_portrait.blank? #=> true
draft.cover_portrait.nil? #=> false
Just upgraded from carrierwave-mongoid 0.1.0 to 0.3.0 via bundle update.
All avatars that my users had uploaded disappeared. Uploading new avatars works fine.
Any way to retrieve them?
Here's my avatar uploader:
# encoding: utf-8
class AvatarUploader < CarrierWave::Uploader::Base
# 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 :fog
# 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
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# # For Rails 3.1+ asset pipeline compatibility:
# # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
#
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
# end
# Process files as they are uploaded:
#process :scale => [80, 80]
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process :scale => [50, 50]
# end
version :profile do
process :resize_to_fill => [80, 80]
end
version :circle do
process :resize_to_fill => [32, 32]
end
version :tiny do
process :resize_to_fill => [22, 22]
end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end
Thanks.
Can we make gridfs dependency optional. I guess for a lot of use cases dont need that extra dependency.
This issue is, for the most part, identical to carrierwaveuploader/carrierwave#836, however to quote @bensie:
Please post mongoid issues on jnicklas/carrierwave-mongoid
# Gemfile
gem 'rails', '3.2.8'
gem 'carrierwave'
gem 'carrierwave-mongoid', :git => "git://github.com/jnicklas/carrierwave-mongoid.git", :branch => "mongoid-3.0", :require => 'carrierwave/mongoid'
gem 'mongoid', '3.0.5'
...
# config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => '...',
:aws_secret_access_key => '...'
},
config.fog_directory = 'uploads'
# other options don't change the result...
end
Here are my tests, although the problem isn't specific to testing.
# spec/uploaders/document_uploader_spec.rb
require 'carrierwave/test/matchers'
require 'tempfile'
require 'spec_helper'
describe DocumentUploader do
include CarrierWave::Test::Matchers
before do
DocumentUploader.enable_processing = true
@uploader = DocumentUploader.new(@user, :avatar)
@uploader.store!(Tempfile.new('foo')) # error thrown here
end
after do
DocumentUploader.enable_processing = false
@uploader.remove!
end
it "should make the image readable only to the owner and not executable" do
@uploader.should have_permissions(0600)
end
end
# app/uploaders/document_uploader.rb
class DocumentUploader < CarrierWave::Uploader::Base
permissions 0600
end
Any time I try storing a file the error is not a recognized storage provider
is thrown. The exact error from the tests is:
Failure/Error: @uploader.store!(Tempfile.new('foo'))
ArgumentError:
is not a recognized storage provider
Using :file
storage works just fine and all tests pass, its only when switching to :fog
that the problem comes up.
I really don't think this is a mongoid issue, I haven't seen anything to justify it as a culprit. This error has also come up in carrierwaveuploader/carrierwave#770, but it seems to be caused by a different problem.
Hi,
I am trying to set carierwave with Mongoid but in new wersion Mongoid.database is undefined. What is new name of Mongoid.database method?
Bundler could not find compatible versions for gem "mongoid":
In Gemfile:
carrierwave-mongoid (>= 0.2.0) ruby depends on
mongoid (~> 2.1) ruby
mongoid (3.0.9)
I am uploading .mov files. Firefox mandates that I convert to ogg for html5 support from their browser.
Here is my version and processor...
def ogg_version
`ffmpeg2theora #{self.path}`
end
version :ogg do
process :ogg_version
end
The files get processed, but the .ogv version gets stuck in tmp, while these files get stored as my versions.
./uploads/../file.mov
./uploads/../ogg_file.mov
Here is the video class that :mov is mounted on.
require 'file_size_validator'
class Video
include Mongoid::Document
include Mongoid::Timestamps
mount_uploader :mov, MovUploader
validates :mov,
:file_size => {
:maximum => 20.megabytes.to_i
}
end
Any ideas?
My environment:
ruby 1.9.2p180
Rails 3.1.0
mongoid-2.2.0
carrierwave-mongoid-0.1.2
Thanks,
Steve
I noticed a (tiny) bug when I tried to update an instance of a model whose the related uploader had a custom store_dir based on a field from the model itself.
module Locomotive
class ThemeAssetUploader < ::CarrierWave::Uploader::Base
def store_dir
self.build_store_dir('sites', model.site_id, 'theme', model.folder)
end
....
end
class ThemeAsset
...
mount_uploader :source, ThemeAssetUploader, :mount_on => :source_filename
...
end
So, if I modify the folder field of an existing instance, the previous file is not deleted. Actually, that's not my issue because the workaround is this case is to call source_filename_will_change! before validating the model.
Except that source_filename_will_change! from Mongoid does not have the same behaviour as the one in AR. Thus, even if you call xxx_will_change!, xxx_changed? won't be true unless you modify its value directly.
The reason behind this behavior is that mongoid still compares the current value and the previous one when calling xxx_changed?. AR instead just checks if the attribute is included in the hash of modified attributes (will_change! puts the attribute in this hash).
Right now, I don't have time to figure out a nice way to solve this. And to be honest, I think that has to be fixed in mongoid.
Anyway, what I came up with in order to force the will_change! stuff is the following line:
my_theme_asset.changed_attributes[:source_filename] = nil
At least, the problem has been tracked down.
thanks
Did
trying to save a image from a get parameter, it uploads, but when i try to get the url, it returns can't convert nil into String
describe "upload" do
before :each do
file_param = 'http://localhost:9292/test/test2.jpg'
f = open( file_param )
filename = File.basename(file_param)
uploaded_file = CarrierWave::SanitizedFile.new :tempfile => f,
:filename => filename, :content_type => f.content_type
@n = Document.new
@n.file = uploaded_file
@n.environment = 'test'
@n.ext_id = 'id'
@n.callback_server = 'http://local'
@n.save
end
it "valid" do
@n.should be_valid
@n.file.should_not be_nil
@n.file.url.should_not be_nil # <- fails here
end
end
hi,
I am having problems uploading images from the form. But it was working fine when i trigger it manually from command line.
this is the error msg i am getting
Cannot serialize an object of class ActionDispatch::Http::UploadedFile into BSON.
my models are
class Offer
include Mongoid::Document
field :name, :type => String
has_one :image
end
class Image
include Mongoid::Document
field :name, :type => String
mount_uploader :asset, ImageUploader
belongs_to :offer
end
and the view is
<%= form_for @offer , :html => {:method => :post, :multipart => true} do |f| %>
<%= f.label :name %>
<%= f.text_field :name %> <br>
<%= f.label :image %>
<%= f.file_field :image %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
and the controller
def create
@offer = Offer.new(params[:offer])
respond_to do |format|
if @offer.save
format.html { redirect_to(@offer, :notice => 'Offer was successfully created.') }
format.xml { render :xml => @offer, :status => :created, :location => @offer }
else
format.html { render :action => "new" }
format.xml { render :xml => @offer.errors, :status => :unprocessable_entity }
end
end
end
i am getting the error on the controller first line itself when assining 'Offer.new(params[:offer])'
You can download the test source code from here https://github.com/Rameshv/test-upload
hi,
there s a new api for the current gridfs ruby driver (latest mongoid uses it)
http://mongotips.com/b/ruby-driver-gridfs-api-now-cleaner-and-faster/
and there are more options that can be set for storing the files.
http://api.mongodb.org/ruby/current/file.GridFS.html
sample:
# Saving IO data
file = File.open("me.jpg")
id2 = @grid.put(file,
:filename => "my-avatar.jpg"
:content_type => "application/jpg",
:_id => 'a-unique-id-to-use-in-lieu-of-a-random-one',
:chunk_size => 100 * 1024,
:metadata => {'description' => "taken after a game of ultimate"})
IMPORTANT:
id2 = @grid.put(image, "my-avatar.jpg", :safe => true)
currently with latest mongoid i wasnt able to access the content-type
i had to save it manually to my model which includes the uploader
It would be great if we could define these options somewhere and that content-type works again.
best regards
I am not sure if this is due to the way I am handling/saving embedded mongoid documents, but I recently came across this issue:
Given a Mongoid document with the following embedded document:
embeds_many :my_embedded_documents, :cascade_callbacks => true
And the embedded document with the following fields:
field :url
field :text
field :note
mount_uploader :image, ImageUploader
When I try to create and save a new embedded document with an image attached, I get the following error:
/home/kclair/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.9/lib/mongoid/criteria.rb:328:in `raise_invalid'
/home/kclair/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.9/lib/mongoid/criteria.rb:307:in `search'
/home/kclair/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.9/lib/mongoid/criterion/inclusion.rb:125:in `find'
/home/kclair/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.4.9/lib/mongoid/relations/embedded/many.rb:251:in `find'
/home/kclair/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-mongoid-0.2.0/lib/carrierwave/mongoid.rb:63:in `find_previous_model_for_image'
/home/kclair/.rvm/gems/ruby-1.9.2-p290/gems/carrierwave-0.6.2/lib/carrierwave/mount.rb:240:in `store_previous_model_for_image'
This is because it is a brand new embedded document, and of course there is no previous model to be found.
I'm not sure if there's a way I could be saving the embedded document that would not cause the error.
This patch fixes the issue for me:
kclair/carrierwave-mongoid@e9896ad
When i try a upload i get
undefined method `bson_dump' for #ActionDispatch::Http::UploadedFile:0x9b96fc8
Is it possible to release the 3.0 branch as a gem? Right now it is not possible to use carrierwave-mongoid as a gem dependency when using mongoid 3.0.
Using the 3.0 branch with latest versions of mongoid, I'm running into this annoying issue dealing with an embeds_many relationship. Here's an abbreviated example of the view:
- @listings.each do |listing|
= for photo in listing.photos.limit(1)
= image_tag photo.image_url
That's outputting the image_tag (which is good) along with the entirety of the embedded object data in the view immediately after:
<img alt="Listing" src="http://path/to/photo/500ca98fae24c2bb41000009/example.jpg">
[#Photo _id: 500ca98fae24c2bb41000009, _type: nil, created_at: 2012-07-23 01:31:59 UTC, caption: "lorem ipsum dolor sit amet consectetuer adipiscing elit proin risus", image: "listing.jpg">]
I'm hoping it's just late and I'm not thinking straight but this is driving me nuts without much luck. I'd definitely appreciate any thoughts you might have.
rails server
DEPRECATION WARNING: ActiveSupport::Memoizable is deprecated and will be removed in future releases,
simply use Ruby memoization pattern instead.
(called from <top (required)> at /Users/lam/workspaces/ys/config/application.rb:12)
application.rb
10 if defined?(Bundler)
11 # If you precompile assets before deploying to production, use this line
12 Bundler.require(*Rails.groups(:assets => %w(development test)))
13 # If you want your assets lazily compiled in production, use this line
14 # Bundler.require(:default, :assets, Rails.env)
15 end
Rails: 3.2.1
carrierwave: 0.5.8
carrierwave-mongoid: 0.1.3
find_previous_model_for_<column>
blows up with the following:
undefined method `find' for #<EmbeddedObject:0x007ff26caf0b48>`
It looks like the cleanup routine was only designed to handle embeds_many
associations and cannot handle an embeds_one
association.
What happens in an embeds_one
scenario is that the previous version of the object tries to find itself using a find
method that doesn't exist.
I have Message model which embeds many Attachments. Attachment model, of course, contain carrierwave uploader.
When I change attachment`s uploader and try to save this document I get NoMethodError. All this because I have a default scope on my Message model and not all documents are contained in this scope.
hay i have a proyect with
mongoid (3.0.4)
mini_magick (3.4)
bson_ext (1.6.4)
i have tried to generate an upload image but it dont work.
are the carrierwave and mongoid ~> 3.0 incompatible?
the carrierwave.rb its looks like this
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid::Config.sessions[:default][:database]
config.grid_fs_host = Mongoid::Config.sessions[:default][:hosts].first
config.storage = :grid_fs
config.grid_fs_access_url = "/images"
end
but puts an error :
undefined method grid_fs_database=' for CarrierWave::Uploader::Base:Class (NoMethodError) from /Users/juannn91/.rvm/gems/ruby-1.9.3-p194/gems/carrierwave-0.6.2/lib/carrierwave/uploader/configuration.rb:97:in
configure'
from /Users/juannn91/.rvm/gems/ruby-1.9.3-p194/gems/carrierwave-0.6.2/lib/carrierwave.rb:15:in `configure'
...
there is a solution for that?
thanks
In user model, I have:
mount_uploader :avatar, AvatarUploader
but user.to_hash["avatar"] => nil
1.9.2p290 :013 > u = User.where(:username => "mark").first
=> #<User _id: 4f05b77de138235417000004, _type: nil, created_at: 2012-01-05 14:45:17 UTC, updated_at: 2012-01-05 18:24:44 UTC, avatar_filename: "spring3.jpg", username: "mark", email: "[email protected]", avatar: nil, first_name: "Mark", last_name: "Ford", country: "US", state: nil, city: nil, zipcode: nil, lng: nil, lat: nil, sex: nil, file_id: nil, last_status_message: "Bon nam sau\r\n", last_status_id: "4f05eaece13823431500001b", crypted_password: "99e0ec4584e875a25b7b87cb6fc75719", salt: "75aac32e79a691471a7306b7907d1fa18d0a9356", time_zone: nil, follower_of: 3, leader_of: 3, confirmed: false, enabled: true, promoter: nil, photographer: nil, profile_private: false, bio: "Sed et quo vel occaecati ratione. Ipsam voluptas corporis repudiandae eaque exercitationem ea pariatur. Dolores et magnam earum ipsa et quasi omnis aut. Cumque assumenda praesentium ullam expedita officiis qui nulla.Et omnis doloribus incidunt nam sit in deleniti autem. Atque aperiam et est iusto nihil. Beatae rem est sit ut debitis dolor est.", date_of_birth: nil, last_visited_at: nil, token_id: nil, token_expire_at: nil, phone: nil>
1.9.2p290 :014 > u.avatar
=> /people/4f05b77de138235417000004/spring3.jpg
1.9.2p290 :015 > u.to_hash
=> {"id"=>"4f05b77de138235417000004", "avatar_filename"=>"spring3.jpg", "bio"=>"Sed et quo vel occaecati ratione. Ipsam voluptas corporis repudiandae eaque exercitationem ea pariatur. Dolores et magnam earum ipsa et quasi omnis aut. Cumque assumenda praesentium ullam expedita officiis qui nulla.Et omnis doloribus incidunt nam sit in deleniti autem. Atque aperiam et est iusto nihil. Beatae rem est sit ut debitis dolor est.", "confirmed"=>false, "country"=>"US", "created_at"=>"2012-01-05 14:45:17 UTC", "crypted_password"=>"99e0ec4584e875a25b7b87cb6fc75719", "email"=>"[email protected]", "enabled"=>true, "first_name"=>"Mark", "follower_of"=>3, "last_name"=>"Ford", "last_status_id"=>"4f05eaece13823431500001b", "last_status_message"=>"Bon nam sau\r\n", "leader_of"=>3, "profile_private"=>false, "salt"=>"75aac32e79a691471a7306b7907d1fa18d0a9356", "updated_at"=>"2012-01-05 18:24:44 UTC", "username"=>"mark"}
1.9.2p290 :016 > u.to_json
=> "{"id":"4f05b77de138235417000004","_id":"4f05b77de138235417000004","avatar_filename":"spring3.jpg","bio":"Sed et quo vel occaecati ratione. Ipsam voluptas corporis repudiandae eaque exercitationem ea pariatur. Dolores et magnam earum ipsa et quasi omnis aut. Cumque assumenda praesentium ullam expedita officiis qui nulla.Et omnis doloribus incidunt nam sit in deleniti autem. Atque aperiam et est iusto nihil. Beatae rem est sit ut debitis dolor est.","confirmed":false,"country":"US","created_at":"2012-01-05T14:45:17Z","crypted_password":"99e0ec4584e875a25b7b87cb6fc75719","email":"[email protected]","enabled":true,"first_name":"Mark","follower_of":3,"last_name":"Ford","last_status_id":"4f05eaece13823431500001b","last_status_message":"Bon nam sau\r\n","leader_of":3,"profile_private":false,"salt":"75aac32e79a691471a7306b7907d1fa18d0a9356","updated_at":"2012-01-05T18:24:44Z","username":"mark"}"
1.9.2p290 :017 > u.to_hash["avatar"]
=> nil
1.9.2p290 :018 >
I got following message while running bundle install in a Ruby 1.9.3, Rails 4.0.0.rc1 setup:
←[31mBundler could not find compatible versions for gem "mongoid":
In Gemfile:
carrierwave-mongoid (~> 0.6.0) x86-mingw32 depends on
mongoid (~> 3.0.1) x86-mingw32
mongoid (4.0.0)←[0m
Hello,
I have an Asset
document that mounts an AssetUploader
uploader and is its embedded in an AssetCollection
document:
class AssetCollection
include Mongoid::Document
include Mongoid::Timestamps
embeds_many :assets, cascade_callbacks: true
end
class Asset
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :asset_collection
mount_uploader :file, AssetUploader
end
When I delete an asset from its collection by calling for example:
collection = ... # assume this exists
asset = collection.assets().last()
asset.delete!
The asset
object is properly deleted and removed from its parent, but the GridFS stays untouched, i.e. the actual file and its chunks are not deleted from the store.
I have no idea of why it happens and I would greatly appreciate some guidance.
Thanks!
Cam
Details of the software versions involved:
Using mongo (1.7.0)
Using mongoid (2.5.0)
Using carrierwave (0.6.2)
Using carrierwave-mongoid (0.2.0)
Hi,
I reached a limit where carrierwave-mongoid can not open further network connections to MongoDB due to too many opened ports on the client machine. After a quick investigation it appears that carrierwave-mongoid does not close its connections quickly enough. When the available connections run out I get this error:
Mongo::ConnectionFailure: Operation failed with the following exception: connection closed
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:327:in `rescue in receive_message_on_socket'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:312:in `receive_message_on_socket'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:184:in `receive_header'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:171:in `receive'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/networking.rb:135:in `receive_message'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/cursor.rb:469:in `block in send_initial_query'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/util/logging.rb:28:in `instrument'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/cursor.rb:467:in `send_initial_query'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/cursor.rb:458:in `refresh'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/cursor.rb:128:in `next'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/db.rb:505:in `command'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/connection.rb:623:in `check_is_master'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/connection.rb:400:in `connect'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/connection.rb:574:in `setup'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongo-1.5.2/lib/mongo/connection.rb:104:in `initialize'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/carrierwave-mongoid-0.1.5/lib/carrierwave/storage/grid_fs.rb:91:in `new'
... 49 levels...
from (irb):16:in `block in irb_binding'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/contexts/mongo.rb:261:in `block in iterate'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/cursor.rb:50:in `block in each'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/collections/retry.rb:29:in `retry_on_connection_failure'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/cursor.rb:48:in `each'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/contexts/mongo.rb:261:in `iterate'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/criteria.rb:145:in `block in each'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/criteria.rb:145:in `tap'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/mongoid-2.4.5/lib/mongoid/criteria.rb:145:in `each'
from (irb):15:in `map'
from (irb):15
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/commands/console.rb:47:in `start'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/commands/console.rb:8:in `start'
from /var/www/az_app_2_production/shared/bundle/ruby/1.9.1/gems/railties-3.2.5/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'1.9.3p125
and by running a netstat -an
it get a enormous list of this kind of entry:
tcp 0 0 213.56.106.35:34009 213.56.106.187:27017 TIME_WAIT
For info, I run into this issue only when executing loops like this in rails console User.all.map { |e| e.valid? }
Is there a way to only use one connection to the GridFS storage or to close the connections more quickly? I can of course get more logs if needed.
Thanks a lot for your help!
Bastien
This is actually a regression which happened after 0.1.3
Please change the CarrierWave::Storage::GridFS#url method back to what it was before, e.g.
[@uploader.grid_fs_access_url, @path].join("/").squeeze("/")
Thanks.
#11
I upgraded to Mongoid 2.4.5 to get compatibility with Rails 3.2. Unfortunately for my app this broke carrierwave-mongoid. I walked versions down until I found the issue cropped up around Mongoid 2.4.0
What I'm seeing is
"Cannot serialize an object of class ActionDispatch::Http::UploadedFile into BSON"
when one uploads a file to a model with an attached mount. I spent hours trying to figure out what's going on but didn't get too far. It seems that fundamentally it's not able to commit the data to the database.
This was working prior to the upgrade, so it's not the normal suspects for this error like improperly named fields and the like. Reverting back to Mongoid 2.3.4, which is what I was using, works.
Environment: Ruby 1.9.3-p327, Rails 3.2.9, Mongoid 3.0.9, Carrierwave-Mongoid 0.3.0
What is the correct way to configure a connection to a mongo database outside the scope of my Rails application? I have tried this in my config block:
config.grid_fs_connection Moped::Session.new([ "127.0.0.1:27017" ]).use "thumbs_grid"
This results in an error. I thought maybe this was the new method to establish a connection. I was used to using the config.grid_fs_database, etc. methods for connections.
Thanks!!
I'm having the same issue that was brought up here:
I have Mongoid 2.2.1 installed on Ubuntu Natty. Any ideas?
$ sudo gem install carrierwave-mongoid
ERROR: While executing gem ... (NameError)
uninitialized constant Syck::Syck
So I switched from MM to Mongoid yesterday and while new uploads work fine, existing uploads stop working because the field we mount the uploader on is set to nil.
e.g. if you have:
class Foo
field :name, type: String
mount_uploader :image, ImageUploader
end
And a record where you've uploaded a_funny_cat.gif
, then after switching from MM => Mongoid and replacing mm-carrierwave with carrierwave-mongoid your object will look like:
f = Foo.first
f.attributes # => { "name" => 'My Cat Gif', "image_filename" => "a_funny_cat.gif" }
f.image # => nil
Note the lack of image
attribute.
You can restore your uploaders by using the mongo console or non-carrierwave code to assign Foo#image = Foo#image_filename, but that's a bit of a hassle and it seems like the library should not be damaging existing records in the first place.
Carrierwave was updated to 0.8.0. This version is supported?
Ran into this when running the tire:import rake task. The options param in serializable_hash defaults to nil which raises an error when what is expected to be a hash is read inside the function. Setting it instead to {} resolves the issue. Issuing a pull request with the change now.
undefined method []' for nil:NilClass /Users/jnsears/.rvm/gems/ruby-1.9.3-p194@global/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:67:in
block in serializable_hash'
/Users/jnsears/.rvm/gems/ruby-1.9.3-p194@global/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:66:in each' /Users/jnsears/.rvm/gems/ruby-1.9.3-p194@global/gems/carrierwave-mongoid-0.3.0/lib/carrierwave/mongoid.rb:66:in
serializable_hash'
When i have tried to run mongoid 3.2.1 with carrierwave-mongoid gem it gives me compatibilty issue
Bundler could not find compatible versions for gem "mongoid":
In Gemfile:
carrierwave-mongoid (>= 0) java depends on
mongoid (~> 3.0.0) java
mongoid (3.1.2)
I upgraded from 0.1.0 to 0.3.0 and now the images are not available at all. I am getting a nil value for all of my images. This is resulting from running User.first.image.first.image_url. When running User.first.image.first.image I get a blank result. After going back to 0.1.0 my images are available again and I can see an actual image location.
class User
include Mongoid::Document
field :name, type: String
field :email, type: String
embeds_many :images, cascade_callbacks: true
end
class Image
include Mongoid::Document
mount_uploader :image, ImageUploader
embedded_in :user
end
Since this commit: carrierwaveuploader/carrierwave@5939074 carrierwave is passing an options parameter to the url method of File, so it no longer works with the latest version of carrierwave-mongoid.
I am running thin on a Windows machine with carrierwave-mongoid and gridfs. My log keeps giving me this:
fatal (deadlock detected):
lib/serve_gridfs_attachment.rb:10:in `call'
Which isn't good because it's causing everything to lock up. Anyone have any idea why I might be getting a deadlock? I can provide more information if you tell me what you need.
Thanks
I understand, that carrierwave-mongoid has moved out of carrierwave, but where has the orm gone?! I'm getting a
‘‘‘
`require': no such file to load -- carrierwave/orm/mongoid
‘‘‘
from the initializer, as the the gridfs-store has been moved, but not the mount_uploader for mongoid: is this intentional or just an omission?!
thx
Stefan
Seems like we need someone to help with maintenance for this gem. Is anyone seeing this interested?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.