Module: Uploadcare::Rails::ActionView::Helpers

Defined in:
lib/uploadcare/rails/action_view.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(arg) ⇒ Object



37
38
39
# File 'lib/uploadcare/rails/action_view.rb', line 37

def self.included(arg)
  ActionView::Helpers::FormBuilder.send(:include, Uploadcare::Rails::ActionView::FormBuilder)
end

Instance Method Details

#uploadcare_include_tag(options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/uploadcare/rails/action_view.rb', line 3

def uploadcare_include_tag(options = {})
  s = Rails.application.config.uploadcare

  src = ''
  s.get_widget_settings.each do |k, v|
    src << "UPLOADCARE_#{k.to_s.underscore.upcase} = \"#{j(v)}\";\n"
  end
  settings_code = javascript_tag(src)

  version = options[:version] || s.widget_version
  min = options[:min].nil? || options[:min]
  url = "https://ucarecdn.com/widget/#{version}/uploadcare/uploadcare-#{version}#{'.min' if min}.js"
  include_code = javascript_include_tag(url)

  settings_code + include_code
end

#uploadcare_uploader_field(object_name, method, options = {}) ⇒ Object



32
33
34
35
# File 'lib/uploadcare/rails/action_view.rb', line 32

def uploadcare_uploader_field(object_name, method, options = {})
  options = uploadcare_uploader_options(options)
  hidden_field(object_name, method, options)
end

#uploadcare_uploader_options(options) ⇒ Object



20
21
22
23
24
25
# File 'lib/uploadcare/rails/action_view.rb', line 20

def uploadcare_uploader_options(options)
  options.symbolize_keys.deep_merge({
    :role => "#{options[:role]} uploadcare-uploader",
    :data => {:path_value => true}
  })
end

#uploadcare_uploader_tag(name, options = {}) ⇒ Object



27
28
29
30
# File 'lib/uploadcare/rails/action_view.rb', line 27

def uploadcare_uploader_tag(name, options = {})
  options = uploadcare_uploader_options(options)
  hidden_field_tag(name, nil, options)
end