Sha256: ff76c2a00275725f030a280a4592d47a9b043959c89e01949b50e9f7ba53e4a1

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

Tori
===

Tori is a very very simple file uploader.

Tori dose nothing.

Only file upload to backend store.

You can upload file without alter database.

# Quick start on Rails

Gemfile

```
gem 'tori', require: 'tori/rails'
```

app/models/photo.rb

```ruby
class Photo < ActiveRecord::Base
  tori :image
end
```

app/controllers/photos_controller.rb

```ruby
class PhotosController < ApplicationController
  def new
    @photo = Photo.new
  end

  def create
    Photo.create(photo_params)
    redirect_to root_path
  end

  private

    def photo_params
      params.require(:photo).permit(:image)
    end
end
```

app/views/photos/new.html.slim

```ruby
= form_for @photo, multipart: true |f|
  = f.file_field 'image'
  = f.button 'Upload'
```

# default configure

```
# Tori using hash function for decide filename.
# Filename dependent on class name and `id` setting with `tori` method in class.
Tori.config.hash_method = Digest::MD5.method(:hexdigest)

# Rails
Tori.config.backend = Tori::Backend::FileSystem.new(Rails.root.join('tmp', 'tori'))

# Other
Tori.config.backend = Tori::Backend::FileSystem.new(Pathname("tmp/tori"))
```

You can change configure any time.

# Options

Change hash resource data.

```
class Photo < ActiveRecord::Base
  tori :image, id: :filename
  def filename
    "abc"
  end
end
```

This class never upload two file.

# future TODO

- support background S3 Storage

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tori-0.0.1 README.md