Tuesday, January 29, 2013

rails engine initializer to add upload path


sample: lib/mymodule/lib/mymodule/engine.rb

module MyModule
  class Engine < ::Rails::Engine
    isolate_namespace MyModule
    #dependency setting is important here
    initializer 'Entcommerce.initialize_upload', :after=> :disable_dependency_loading do |app|
      #Rails.logger.debug "Root: " + Rails.root.to_s
      config.upload_path = Rails.root.join("assets").join("images").join("product")
      #Rails.logger.debug "upload_path: " + config.upload_path.to_s
    end
  end
end



#To get this setting from controller
Rails.application.config.upload_path

reference:

No comments: