Class: Engine2::DownloadFileStoreAction

Inherits:
Action show all
Defined in:
lib/engine2/action/infra.rb

Instance Attribute Summary

Attributes inherited from Action

#assets, #invokable, #meta, #node, #static

Instance Method Summary collapse

Methods inherited from Action

action_type, #action_type, #arguments, #check_anonymous_action_class, #check_static_action, #define_invoke, #define_method, #dynamic?, #execute, #freeze_action, #http_method, http_method, inherit, inherited, #initialize, #invoke!, #join_keys, #lookup, #merge, #node_defined, #post_process, #post_run, #pre_run, #repeat, #request, #request_action_proc_params, #split_keys

Constructor Details

This class inherits a constructor from Engine2::Action

Instance Method Details

#invoke(handler) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/engine2/action/infra.rb', line 94

def invoke handler
    handler.permit id = handler.params[:id]
    entry = E2Files.db[:files].select(:name, :mime)[id: id]
    handler.permit entry
    handler.attachment entry[:name]
    handler.content_type (entry[:mime].to_s.empty? ? "application/octet-stream" : entry[:mime])
    info = node.parent.*.model.type_info[node.parent.*.field]
    open("#{info[:store][:files]}/#{entry[:name]}_#{id}", 'rb'){|f|f.read}
end