diff --git a/config/routes.rb b/config/routes.rb deleted file mode 100644 index cd19dbe..0000000 --- a/config/routes.rb +++ /dev/null @@ -1,4 +0,0 @@ -CarrierWave::Mongoid::Media.routes.draw do - get 'media/*path' => 'media#show' -end - diff --git a/lib/carrierwave-mongoid-media/engine.rb b/lib/carrierwave-mongoid-media/engine.rb index 6a5f2a3..9456067 100644 --- a/lib/carrierwave-mongoid-media/engine.rb +++ b/lib/carrierwave-mongoid-media/engine.rb @@ -1,9 +1,27 @@ +require 'carrierwave' + module CarrierWave module Mongoid class Media < ::Rails::Engine - initializer 'carrierwave_mongoid_media.carrierwave' do + DEFAULT_PREFIX = :media + + class << self + attr_writer :prefix + end + + def self.prefix + @prefix ||= DEFAULT_PREFIX + end + + def self.routes(router, prefix = :media) + self.prefix = prefix + CarrierWave.configure do |c| - c.grid_fs_access_url = '/media' + c.grid_fs_access_url = "/#{prefix}" + end + + router.instance_exec do + get "#{prefix}/*path" => "media#show", :as => :media end end end