### Home Classes Methods

### In Files

- lib/ramaze/helper/upload.rb

### Methods

- #handle_uploads_for
- #upload_options

### Included Modules

- Ramaze::Traited

### Class/Module Index

Quicksearch

- Ramaze
- Ramaze::App
- Ramaze::AppGraph
- Ramaze::Bin
- Ramaze::Bin::Console
- Ramaze::Bin::Create
- Ramaze::Bin::Helper
- Ramaze::Bin::Restart
- Ramaze::Bin::Runner
- Ramaze::Bin::Start
- Ramaze::Bin::Status
- Ramaze::Bin::Stop
- Ramaze::Cache
- Ramaze::Cache::LRU
- Ramaze::Cache::LocalMemCache
- Ramaze::Cache::MemCache
- Ramaze::Cache::Redis
- Ramaze::Cache::Sequel
- Ramaze::Controller
- Ramaze::CoreExtensions
- Ramaze::CoreExtensions::Array
- Ramaze::CoreExtensions::Binding
- Ramaze::CoreExtensions::Kernel
- Ramaze::CoreExtensions::Numeric
- Ramaze::CoreExtensions::Object
- Ramaze::CoreExtensions::Proc
- Ramaze::CoreExtensions::String
- Ramaze::Current
- Ramaze::DefaultController
- Ramaze::Dictionary
- Ramaze::Fiber
- Ramaze::Files
- Ramaze::GemSetup
- Ramaze::Gestalt
- Ramaze::Helper
- Ramaze::Helper::Auth
- Ramaze::Helper::Bench
- Ramaze::Helper::BlueForm
- Ramaze::Helper::BlueForm::Form
- Ramaze::Helper::CSRF
- Ramaze::Helper::Cache
- Ramaze::Helper::Cache::SingletonMethods
- Ramaze::Helper::Disqus
- Ramaze::Helper::Email
- Ramaze::Helper::Erector
- Ramaze::Helper::Flash
- Ramaze::Helper::Formatting
- Ramaze::Helper::Gestalt
- Ramaze::Helper::Gravatar
- Ramaze::Helper::Identity
- Ramaze::Helper::Layout
- Ramaze::Helper::Layout::SingletonMethods
- Ramaze::Helper::Link
- Ramaze::Helper::Localize
- Ramaze::Helper::Localize::Dictionary
- Ramaze::Helper::Localize::Parser
- Ramaze::Helper::Markaby
- Ramaze::Helper::Maruku
- Ramaze::Helper::Paginate
- Ramaze::Helper::Paginate::Paginator
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Ramaze::Helper::Paginate::Paginator::DataMapperPager
- Ramaze::Helper::Remarkably
- Ramaze::Helper::RequestAccessor
- Ramaze::Helper::SendFile
- Ramaze::Helper::SimpleCaptcha
- Ramaze::Helper::Stack
- Ramaze::Helper::Thread
- Ramaze::Helper::Ultraviolet
- Ramaze::Helper::Upload
- Ramaze::Helper::Upload::ClassMethods
- Ramaze::Helper::Upload::UploadedFile
- Ramaze::Helper::UserHelper
- Ramaze::Helper::UserHelper::Wrapper
- Ramaze::Helper::XHTML
- Ramaze::LRUHash
- Ramaze::Logger
- Ramaze::Logger::Analogger
- Ramaze::Logger::Growl
- Ramaze::Logger::Informer
- Ramaze::Logger::Knotify
- Ramaze::Logger::LogHub
- Ramaze::Logger::Logger
- Ramaze::Logger::RotatingInformer
- Ramaze::Logger::Syslog
- Ramaze::Logger::Xosd
- Ramaze::Logging
- Ramaze::MiddlewareCompiler
- Ramaze::Plugin
- Ramaze::Reloader
- Ramaze::Reloader::Hooks
- Ramaze::Reloader::WatchInotify
- Ramaze::Reloader::WatchStat
- Ramaze::Reloader::Watcher
- Ramaze::Request
- Ramaze::Response
- Ramaze::SpecLogger
- Ramaze::Struct
- Ramaze::View
- Ramaze::View::Erector
- Ramaze::View::Erubis
- Ramaze::View::Ezamar
- Ramaze::View::Gestalt
- Ramaze::View::Haml
- Ramaze::View::Liquid
- Ramaze::View::Liquid::Tag
- Ramaze::View::Lokar
- Ramaze::View::Mustache
- Ramaze::View::Mustache::RamazeContext
- Ramaze::View::Nagoro
- Ramaze::View::Remarkably
- Ramaze::View::Sass
- Ramaze::View::Slippers
- Ramaze::View::Tagz
- Ramaze::View::Tagz::Methods
- Ramaze::View::Tenjin
- Nagoro
- Nagoro::Pipe
- Nagoro::Pipe::RenderPartial
- Bacon
- Bacon::PrettyOutput
- Erector
- Erector::Widget
- Rack
- Rack::RouteExceptions
- Tenjin
- Tenjin::Template
- BlankSlate
- Controller
- Fiber
- FiberError
- MainController
- Object
- OrderedSet
- Thread

No matching classes.

# Ramaze::Helper::Upload::ClassMethods

Helper class methods. Methods in this module will be available in your controller class (not your controller instance).

### Public Instance Methods

handle_uploads_for(*args) click to toggle source

This method will activate automatic handling of uploaded files for specified actions in the controller.

@example

    class MyController < Ramaze::Controller

      # Use upload helper
      helper :upload

      # Handle all uploads for the foo and bar actions
      handle_uploads_for :foo, :bar

      # Handle all uploads for the baz action and uploads beginning with
      # 'up' for the qux action
      handle_uploads_for :baz, [:qux, /^up.*/]
    end

@param *args An arbitrary long list of arguments with action names

    (and optionally patterns) that should handle file uploads
    automatically. Each argument can either be a symbol or a two-element
    array consisting of a symbol and a reqexp.

@see handle_all_uploads @see Ramaze::Helper::Upload#get_uploaded_files

    # File lib/ramaze/helper/upload.rb, line 255
    def handle_uploads_for(*args)
      args.each do |arg|
        if arg.respond_to?(:first) and arg.respond_to?(:last)
          before(arg.first.to_sym) do
            get_uploaded_files(arg.last)
          end
        else
          before(arg.to_sym) do
            get_uploaded_files
          end
        end
      end
    end

upload_options(options) click to toggle source

Sets options for file uploads in the controller.

@example

    # This controller will handle all file uploads automatically.
    # All uploaded files are saved automatically in '/uploads/myapp'
    # and old files are overwritten.
    #
    class MyController < Ramaze::Controller

      # Use upload helper
      helper :upload

      handle_all_uploads
      upload_options :allow_overwrite => true,
                     :autosave => true,
                     :default_upload_dir => '/uploads/myapp',
                     :unlink_tempfile => true
    end

    # This controller will handle all file uploads automatically.
    # All uploaded files are saved automatically, but the exact location
    # is depending on a session variable. Old files are overwritten.
    #
    class MyController2 < Ramaze::Controller

      # Use upload helper
      helper :upload

      # Proc to use for save directory calculation
      calculate_dir = lambda { File.join('/uploads', session['user']) }

      handle_all_uploads
      upload_options :allow_overwrite => true,
                     :autosave => true,
                     :default_upload_dir => calculate_dir,
                     :unlink_tempfile => true
    end

@param [Hash] options Options controlling how file uploads

    are handled.

@option options [Boolean] :allow_overwrite If set to true, uploaded

    files are allowed to overwrite existing ones. This option is set to
    *false* by default.

@option options [Boolean] :autosave If set to true,

    Ramaze::Helper::Upload::UploadedFile#save will be called on all
    matched file uploads
    automatically. You can use this option to automatically save files
    at a preset location, but please note that you will need to set the
    :default_upload_dir (and possibly :allow_overwrite) options as well
    in order for this to work correctly. This option is set to *false*
    by default.

@option options [String|Proc] :default_upload_dir If set to a string

    (representing a path in the file system) this option will allow you
    to save uploaded files without specifying a path. If you intend to
    call Ramaze::Helper::Upload::UploadedFile#save with a path you don't
    need to set this option at all. If you need to delay the calculation
    of the directory, you can also set this option to a proc. The proc
    should accept zero arguments and return a string. This comes in handy
    when you want to use different directory paths for different users
    etc.  This option is set to *nil* by default.

@option options [Boolean] :unlink_tempfile If set to true, this

    option will automatically unlink the temporary file created by Rack
    immediately after Ramaze::Helper::Upload::UploadedFile#save is done
    saving the uploaded file. This is probably not needed in most cases,
    but if you don't want to expose your uploaded files in a shared
    tempdir longer than necessary this option might be for you. This
    option is set to *false* by default.

@see Ramaze::Helper::Upload::UploadedFile#initialize @see Ramaze::Helper::Upload::UploadedFile#save

    # File lib/ramaze/helper/upload.rb, line 339
    def upload_options(options)
      trait(
        :upload_options => Ramaze::Helper::Upload::ClassMethods.trait[
          :default_upload_options
        ].merge(options)
      )
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.