Class: RefileInput
- Inherits:
-
Formtastic::Inputs::FileInput
- Object
- Formtastic::Inputs::FileInput
- RefileInput
- Defined in:
- lib/inputs/refile_input.rb
Instance Method Summary collapse
- #file_input_html_options ⇒ Object
- #hidden_input_html_options ⇒ Object
-
#initialize(*args) ⇒ RefileInput
constructor
A new instance of RefileInput.
- #to_html ⇒ Object
Constructor Details
#initialize(*args) ⇒ RefileInput
2 3 4 5 6 |
# File 'lib/inputs/refile_input.rb', line 2 def initialize *args super @reference = SecureRandom.hex end |
Instance Method Details
#file_input_html_options ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/inputs/refile_input.rb', line 8 def [:data] ||= {} [:data][:reference] = @reference attacher = object.send(:"#{method}_attacher") [:accept] = attacher.definition.accept host = [:host] || Refile.cdn_host if [:direct] backend_name = Refile.backends.key(attacher.cache) url = ::File.join(host, Rails.application.routes.url_helpers.refile_app_path, backend_name) [:data].merge!(direct: true, as: "file", url: url) end if [:presigned] and attacher.cache.respond_to?(:presign) url = ::File.join(host, Rails.application.routes.url_helpers.refile_app_path, backend_name, "presign") [:data].merge!(direct: true, url: url) end .merge() end |
#hidden_input_html_options ⇒ Object
31 32 33 34 |
# File 'lib/inputs/refile_input.rb', line 31 def attacher = object.send(:"#{method}_attacher") { value: attacher.data.to_json, object: object, id: nil, data: { reference: @reference } } end |
#to_html ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/inputs/refile_input.rb', line 36 def to_html input_wrapping do label_html << builder.hidden_field(method, ) << builder.file_field(method, ) << image_preview_content end end |