Module: Ramaze::Helper::Attachments
- Included in:
- CortexReaver::Model::Renderer
- Defined in:
- lib/cortex_reaver/helper/attachments.rb
Overview
Helps with attachments. Requires CRUD.
Class Method Summary collapse
Instance Method Summary collapse
-
#delete_attachment(id, name) ⇒ Object
Deletes an attachment on a model identified by id.
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cortex_reaver/helper/attachments.rb', line 7 def self.included(base) base.instance_eval do # Saves all attachments from a request which match form to model. # Returns true if all were successful. Returns an array of # attachments which were added. def self.(model, ) return unless .respond_to? :each .each do |key, file| if tempfile = file[:tempfile] and filename = file[:filename] and not filename.blank? model.(filename).file = tempfile end end end end end |
Instance Method Details
#delete_attachment(id, name) ⇒ Object
Deletes an attachment on a model identified by id.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cortex_reaver/helper/attachments.rb', line 26 def (id, name) unless @model = model_class.get(id) flash[:error] = "No such #{model_class.to_s.downcase} (#{h id}) exists." redirect rs() end # You need to be able to edit the model before removing attachments! for_auth do |u| u.can_edit? @model end unless = @model.(name) flash[:error] = "No such attachment (#{h name}) exists." redirect @model.url end begin .delete flash[:notice] = "Deleted attachment #{h name}." rescue => e flash[:error] = "Couldn't delete attachment #{h name}: #{h e.}." end redirect @model.url end |