forked from leandro/refile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrails.rb
54 lines (46 loc) · 1.52 KB
/
rails.rb
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
48
49
50
51
52
53
54
require "refile"
require "refile/rails/attachment_helper"
module Refile
# @api private
class Engine < Rails::Engine
initializer "refile.setup", before: :load_environment_config do
if RUBY_PLATFORM == "java"
# Work around a bug in JRuby, see: https://github.com/jruby/jruby/issues/2779
Encoding.default_internal = nil
end
Refile.store ||= Refile::Backend::FileSystem.new(Rails.root.join("tmp/uploads/store").to_s)
Refile.cache ||= Refile::Backend::FileSystem.new(Rails.root.join("tmp/uploads/cache").to_s)
ActiveSupport.on_load :active_record do
require "refile/attachment/active_record"
end
ActionView::Base.send(:include, Refile::AttachmentHelper)
ActionView::Helpers::FormBuilder.send(:include, AttachmentHelper::FormBuilder)
end
initializer "refile.app" do
Refile.logger = Rails.logger
Refile.app = Refile::App.new
end
initializer "refile.secret_key" do |app|
Refile.secret_key ||= if app.respond_to?(:secrets)
app.secrets.secret_key_base
elsif app.config.respond_to?(:secret_key_base)
app.config.secret_key_base
elsif app.config.respond_to?(:secret_token)
app.config.secret_token
end
end
end
end
# Add in missing methods for file uploads in Rails < 4
ActionDispatch::Http::UploadedFile.class_eval do
unless instance_methods.include?(:eof?)
def eof?
@tempfile.eof?
end
end
unless instance_methods.include?(:close)
def close
@tempfile.close
end
end
end