<commit_before># CarrierWave for Mongoid

This gem adds support for Mongoid and MongoDB's GridFS to
[CarrierWave](https://github.com/carrierwaveuploader/carrierwave/)

This functionality used to be part of CarrierWave but has since been extracted
into this gem.

[![Gem Version](http://img.shields.io/gem/v/carrierwave-mongoid.svg)](https://rubygems.org/gems/carrierwave-mongoid) [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave-mongoid.svg)](http://travis-ci.org/carrierwaveuploader/carrierwave-mongoid) [![Code Climate](http://img.shields.io/codeclimate/github/carrierwaveuploader/carrierwave-mongoid.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave-mongoid)

## Installation

Install the latest release:

    gem install carrierwave-mongoid

Require it in your code:

```ruby
require 'carrierwave/mongoid'
```

Or, in Rails you can add it to your Gemfile:

```ruby
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
```

Note: If using Rails 4, you'll need to make sure `mongoid-grid_fs` is `>= 1.9.0`.
If in doubt, run `bundle update mongoid-grid_fs`

```ruby
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
```

## Getting Started

Follow the "Getting Started" directions in the main
[Carrierwave repository](https://raw.github.com/carrierwaveuploader/carrierwave/).

[Suggested] Add the field to your attr_accessor list for mass assignment
protection:

```ruby
attr_accessible :avatar, :avatar_cache
```

Now you can cache files by assigning them to the attribute; they will
automatically be stored when the record is saved. Ex:

```ruby
u = User.new
u.avatar = File.open('somewhere')
u.save!
```

## Using MongoDB's GridFS store

In your uploader, set the storage to `:grid_fs`:

```ruby
class AvatarUploader < CarrierWave::Uploader::Base
  storage :grid_fs
end
```

Bringing it all together, you can also configure Carrierwave to use Mongoid's
database connection and default all storage to GridFS. That might look something
like this:
<commit_msg>Fix link to CarrierWave repository<commit_after># CarrierWave for Mongoid

This gem adds support for Mongoid and MongoDB's GridFS to
[CarrierWave](https://github.com/carrierwaveuploader/carrierwave/)

This functionality used to be part of CarrierWave but has since been extracted
into this gem.

[![Gem Version](http://img.shields.io/gem/v/carrierwave-mongoid.svg)](https://rubygems.org/gems/carrierwave-mongoid) [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave-mongoid.svg)](http://travis-ci.org/carrierwaveuploader/carrierwave-mongoid) [![Code Climate](http://img.shields.io/codeclimate/github/carrierwaveuploader/carrierwave-mongoid.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave-mongoid)

## Installation

Install the latest release:

    gem install carrierwave-mongoid

Require it in your code:

```ruby
require 'carrierwave/mongoid'
```

Or, in Rails you can add it to your Gemfile:

```ruby
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
```

Note: If using Rails 4, you'll need to make sure `mongoid-grid_fs` is `>= 1.9.0`.
If in doubt, run `bundle update mongoid-grid_fs`

```ruby
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
```

## Getting Started

Follow the "Getting Started" directions in the main
[Carrierwave repository](https://github.com/carrierwaveuploader/carrierwave/).

[Suggested] Add the field to your attr_accessor list for mass assignment
protection:

```ruby
attr_accessible :avatar, :avatar_cache
```

Now you can cache files by assigning them to the attribute; they will
automatically be stored when the record is saved. Ex:

```ruby
u = User.new
u.avatar = File.open('somewhere')
u.save!
```

## Using MongoDB's GridFS store

In your uploader, set the storage to `:grid_fs`:

```ruby
class AvatarUploader < CarrierWave::Uploader::Base
  storage :grid_fs
end
```

Bringing it all together, you can also configure Carrierwave to use Mongoid's
database connection and default all storage to GridFS. That might look something
like this:

{'fraction_non_alphanumeric': 0.11528017773389286, 'fraction_numerical': 0.001974821031843989, 'mean_word_length': 5.371069182389937, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5053831', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1250, 'n_words': 392}