Sha256: c23b3fdc710295e95f657fcaa9f64fbf0d351ea2c346bc37d4d319107ac98aa0

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module ActionView::Helpers
  module Tags
    autoload :QiniuUploadField, File.expand_path('../tags/qiniu_upload_field', __FILE__)
  end

  module FormHelper
    # Example
    #   qiniu_upload_field(:object_name, method, html_attr => 'my attr')
    #   qiniu_upload_field(:user, :avatar, 'data-id' => 'id')
    #
    def qiniu_upload_field(object_name, method, options = {})
      Tags::QiniuUploadField.new(object_name, method, self, options).render
    end

    def qiniu_upload_tag(name, value = nil, options = {})
      qiniu_upload_field(nil, nil, options.merge({
        :name => name,
        :value => value
      }))
    end
  end

  class FormBuilder
    self.field_helpers << :qiniu_upload_field

    # Example
    #   f.qiniu_upload_field(:field, :html_attr => 'my data')
    #   f.qiniu_upload_field(:avatar)
    #   f.qiniu_upload_field(:avatar, 'data-id' => 'id')
    #
    def qiniu_upload_field(method, options = {})
      @template.qiniu_upload_field(@object_name, method, objectify_options(options))
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
qiniu_form-0.0.2 lib/qiniu_form/view_helpers/form_helper.rb
qiniu_form-0.0.1 lib/qiniu_form/view_helpers/form_helper.rb