Class: Thoth::MediaController

### Home Classes Methods

### In Files

- lib/thoth/controller/media.rb

### Parent

Ramaze::Controller

### Methods

- #delete
- #edit
- #index
- #list
- #new

### Files

- robots.txt

### Class/Module Index

Quicksearch

- Thoth
- Thoth::AdminController
- Thoth::ArchiveController
- Thoth::Comment
- Thoth::CommentApiController
- Thoth::CommentController
- Thoth::Config
- Thoth::Error
- Thoth::Importer
- Thoth::MainController
- Thoth::Media
- Thoth::MediaController
- Thoth::MinifyController
- Thoth::Page
- Thoth::PageApiController
- Thoth::PageController
- Thoth::Pager
- Thoth::Plugin
- Thoth::Plugin::Delicious
- Thoth::Plugin::Flickr
- Thoth::Plugin::Tags
- Thoth::Plugin::Twitter
- Thoth::Post
- Thoth::PostApiController
- Thoth::PostController
- Thoth::SchemaError
- Thoth::SearchController
- Thoth::Tag
- Thoth::TagApiController
- Thoth::TagController
- Thoth::TagsPostsMap
- Ramaze
- Ramaze::Dispatcher
- Ramaze::Dispatcher::File
- Ramaze::Helper
- Ramaze::Helper::Admin
- Ramaze::Helper::Cookie
- Ramaze::Helper::Error
- Ramaze::Helper::Pagination
- Ramaze::Helper::Sanitize
- Ramaze::Helper::Wiki
- Ramaze::Helper::Ysearch
- Ramaze::Helper::Ysearch::SearchError
- AddMediaSize
- CreateSchema
- PantsImporter
- PoseidonImporter

No matching classes.

# Thoth::MediaController

### Public Instance Methods

delete(id = nil) click to toggle source

    # File lib/thoth/controller/media.rb, line 49
    def delete(id = nil)
      require_auth

      error_404 unless id && @file = Media[id]

      if request.post?
        error_403 unless form_token_valid?

        if request[:confirm] == 'yes'
          @file.destroy
          flash[:success] = 'File deleted.'
          redirect(Rs(:list))
        else
          redirect(Rs(:edit, id))
        end
      end

      @title          = "Delete File: #{@file.filename}"
      @delete         = true
      @show_file_edit = true
    end

edit(id = nil) click to toggle source

    # File lib/thoth/controller/media.rb, line 71
    def edit(id = nil)
      require_auth

      redirect(Rs(:new)) unless id && @file = Media[id]

      @title          = "Edit Media - #{@file.filename}"
      @form_action    = Rs(:edit, id)
      @show_file_edit = true

      if request.post?
        error_403 unless form_token_valid?

        tempfile, filename, type = request[:file].values_at(
            :tempfile, :filename, :type)

        @file.mimetype = type || 'application/octet-stream'

        begin
          unless File.directory?(File.dirname(@file.path))
            FileUtils.mkdir_p(File.dirname(@file.path))
          end

          FileUtils.mv(tempfile.path, @file.path)
          @file.save

          flash[:success] = 'File saved.'
          redirect(Rs(:edit, id))
        rescue => e
          @media_error = "Error: #{e}"
        end
      end
    end

index(filename = nil) click to toggle source

    # File lib/thoth/controller/media.rb, line 38
    def index(filename = nil)
      unless filename && file = Media[:filename => filename.strip]
        error_404
      end

      send_file(file.path)

    rescue Errno::ENOENT => e
      error_404
    end

list(page = 1) click to toggle source

    # File lib/thoth/controller/media.rb, line 104
    def list(page = 1)
      require_auth

      page = page.to_i

      @columns  = [:filename, :size, :created_at, :updated_at]
      @order    = (request[:order] || :asc).to_sym
      @sort     = (request[:sort]  || :filename).to_sym
      @sort     = :created_at unless @columns.include?(@sort)
      @sort_url = Rs(:list, page)

      @files = Media.paginate(page, 20).order(@order == :desc ? @sort.desc :
          @sort)

      @title = "Media (page #{page} of #{[@files.page_count, 1].max})"
      @pager = pager(@files, Rs(:list, '%s', :sort => @sort, :order => @order))
    end

new() click to toggle source

    # File lib/thoth/controller/media.rb, line 122
    def new
      require_auth

      @title       = "Upload Media"
      @form_action = Rs(:new)

      if request.post?
        error_403 unless form_token_valid?

        tempfile, filename, type = request[:file].values_at(
            :tempfile, :filename, :type)

        file = Media.new do |f|
          f.filename = filename
          f.mimetype = type || 'application/octet-stream'
        end

        begin
          unless File.directory?(File.dirname(file.path))
            FileUtils.mkdir_p(File.dirname(file.path))
          end

          FileUtils.mv(tempfile.path, file.path)
          file.save

          flash[:success] = 'File uploaded.'
          redirect(Rs(:edit, file.id))
        rescue => e
          @media_error = "Error: #{e}"
        end
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.