carrierwave-mongoid-media/README.md

25 lines
839 B
Markdown
Raw Permalink Normal View History

2013-02-22 21:58:41 +00:00
Make it very easy to accept Carrierwave uploads to a Mongoid GridFS-backed data store and then deliver them.
2012-10-11 00:45:35 +00:00
2013-02-22 21:58:41 +00:00
Add this to your `config/routes.rb`:
2012-10-11 00:45:35 +00:00
2013-02-22 21:58:41 +00:00
``` ruby
My::Application.routes.draw do
CarrierWave::Mongoid::Media.routes(self)
end
```
2012-10-11 00:45:35 +00:00
2013-03-11 20:21:59 +00:00
And you'll have a `/media/:id` route that just delivers whatever Carrierwave uploads to this app, as long as
2013-02-22 21:58:41 +00:00
you're using [carrierwave-mongoid](https://github.com/jnicklas/carrierwave-mongoid) to do the uploads. CarrierWave's
`grid_fs_access_url` will be set correctly for you, too.
2012-10-11 00:45:35 +00:00
2013-02-22 21:58:41 +00:00
You can specify if any of the paths should respond with `Content-Disposition: attachment` headers with an initializer:
2012-10-11 00:45:35 +00:00
2013-02-22 21:58:41 +00:00
``` ruby
# config/initializers/carrierwave_mongoid_media.rb
2012-10-11 00:45:35 +00:00
2013-03-11 20:21:59 +00:00
CarrierwaveMongoidMedium.force_downloads_on do |path|
2013-02-22 21:58:41 +00:00
# return true if the file should get Content-Disposition: attachment
end
```
2012-10-11 00:45:35 +00:00