Module: SimpleAttachments::ViewHelpers
- Defined in:
- lib/simple_attachments/view_helpers.rb
Defined Under Namespace
Modules: FormHelper, TagHelper
Class Method Summary collapse
-
.helper(type, template, object, object_name, method, options) ⇒ Object
Create
div
with attachments.
Class Method Details
.helper(type, template, object, object_name, method, options) ⇒ Object
Create div
with attachments.
Allowed options
- :text
-
Text in the add button. [nil]
- :id
-
Main div id. [nil]
- :can_destroy
-
Show destroy link. [true]
- :can_create
-
Show add button. [true]
- :readonly
-
Sets default values for :can_destroy and :can_create. [false]
- :destroy_remote
-
Destroy the attachment on the server after clicking the destroy link. [true]
- :auto_associate
-
Associate uploaded file with container at once. Also sets default value for :destroy_remote. [true]
You can also specify any other options and then access them from JavaScript code.
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 |
# File 'lib/simple_attachments/view_helpers.rb', line 18 def self.helper(type, template, object, object_name, method, ) text = .delete :text id = .delete :id [:readonly] = false if [:readonly].nil? [:can_destroy] ||= ![:readonly] [:can_create] ||= ![:readonly] .delete :readonly [:auto_associate] ||= true if [:auto_associate].nil? container_id = ([:auto_associate] ? object.id : nil) [:destroy_remote] ||= [:auto_associate] .delete :auto_associate attached = object.send(method) if attached.is_a? Array attached = attached.map{|a| a.serializable_hash} else attached = attached.serializable_hash unless attached.nil? end = template.send object.class.reflections[method].class_name.pluralize.underscore.concat('_path') template.content_tag(:div, template.content_tag(:div, text, :class => 'simple_attachments_add_file_div'), :class => "simple_attachments_div simple_attachments_#{type}_div", :id => id, :data => {:container_model => object_name, :container_id => container_id, :method => method, :attachments_path => , :attached => attached.to_json, :options => .to_json } ) end |