katafrakt / carrierwave-nobrainer

NoBrainer adapter for CarrierWave
MIT License
3 stars 0 forks source link

CarrierWave::NoBrainer

This project is retired. See the official one.

This is was a NoBrainer adapter for CarrierWave gem.

Please note: This version targets CarrierWave's master branch, which is under development. Expect bugs! (But also some nice features, like arrays of files).

Installation

Add this line to your application's Gemfile:

gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'
gem 'carrierwave-nobrainer', github: 'katafrakt/carrierwave-nobrainer'

And then execute:

$ bundle

Usage

In your model put include CarrierWave::NoBrainer and then follow normal CarrierWave procedure. For example:

class User
  include NoBrainer::Document
  include NoBrainer::Document::Timestamps
  include CarrierWave::NoBrainer

  field :name, type: String, required: true
  field :avatar, type: String
  mount_uploader :avatar, AvatarUploader
end

Unlike ActiveRecord version, CarrierWave's methods are not included automatically to every NoBrainer model. This is because I believe that explicit is better than implicit. If you are not with me, you can add this to your initializer:

NoBrainer::Document.send(:include, CarrierWave::NoBrainer)

Added features

You may pass :filename => 'some_filename.png' to the mount_uploader method options. For example:

mount_uploader :icon, SomeUploader, :filename => 'icon.png'

This will have the effect of not storing this static filename in the document to avoid polluting the DB with useless fields.

Contributing

  1. Fork it ( https://github.com/katafrakt/carrierwave-nobrainer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request