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