aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 7a59bcd18d97ecdccd61bc214efd2598805683ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Active File

...

## Example

```ruby
class Person < ApplicationRecord
  has_one :avatar
end

class Avatar < ApplicationRecord
  belongs_to :person
  belongs_to :image, class_name: 'ActiveFile::Blob'

  has_file :image
end

avatar.image.url(expires_in: 5.minutes)


class ActiveFile::DownloadsController < ActionController::Base
  def show
    head :ok, ActiveFile::Blob.locate(params[:id]).download_headers
  end
end


class AvatarsController < ApplicationController
  def create
    # @avatar = Avatar.create \
    #   image: ActiveFile::Blob.save!(file_name: params.require(:name), content_type: request.content_type, data: request.body)
    @avatar = Avatar.create! image: Avatar.image.extract_from(request)
  end
end


class ProfilesController < ApplicationController
  def update
    @person.update! avatar: @person.avatar.update!(image: )
  end
end
```

## License

Active File is released under the [MIT License](https://opensource.org/licenses/MIT).