Public Instance methods
form_assign(fields, result: shrine_class.opts[:form_assign][:result])
Helper for setting the attachment from form fields. Returns normalized fields.
attacher = Shrine::Attacher.from_entity(photo, :image) attacher.form_assign({ image: file, title: "Title" }) #=> { image: '{...}', title: "Title" } attacher.form_assign({ image: "", image_remote_url: "...", title: "Title" }) #=> { image: '{...}', title: "Title" } attacher.form_assign({ image: "", title: "Title" }) #=> { title: "Title" }
You can also return the result in form of attributes to be used for database record creation.
attacher.form_assign({ image: file, title: "Title" }, result: :attributes) #=> { image_data: '{...}', title: "Title" }
[show source]
# File lib/shrine/plugins/form_assign.rb 36 def form_assign(fields, result: shrine_class.opts[:form_assign][:result]) 37 form = create_form_object 38 fields = form_write(form, fields) 39 40 form_attach(form) 41 42 form_result(fields, result) 43 end