Sha256: 9af806bfa6ff77898dea5853aee6dd0ce69cc2da6e7bd863de0a143f6d216c1a

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 KB

Contents

Gem.loaded_specs['ouvrages_file_uploader'].dependencies.each do |dependency|
  require dependency.name
end

require "ouvrages_file_uploader/engine"

module OuvragesFileUploader
  module ActiveRecordHelpers
    def accepts_uploaded_file_for(attachment)
      attachment_uploaded_file_id = "#{attachment}_uploaded_file_id"
      attr_reader attachment_uploaded_file_id.to_sym
      attr_accessible attachment_uploaded_file_id.to_sym
      define_method("#{attachment_uploaded_file_id}=") do |id|
        unless id.blank?
          instance_variable_set("@#{attachment_uploaded_file_id}", id)
          if uploaded_file = UploadedFile.where(id: id).first
            self.send("#{attachment}=",  File.open(uploaded_file.file.path))
          end
        end
      end
    end
  end
  module Helpers
    def file_upload(form, attachment, options = {})
      render partial: "/uploaded_files/file_upload", locals: { form: form, attachment: attachment, options: options.with_indifferent_access}
    end
  end
end

ActiveRecord::Base.extend OuvragesFileUploader::ActiveRecordHelpers
ActionController::Base.send(:helper, OuvragesFileUploader::Helpers)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ouvrages_file_uploader-0.0.3 lib/ouvrages_file_uploader.rb
ouvrages_file_uploader-0.0.2 lib/ouvrages_file_uploader.rb
ouvrages_file_uploader-0.0.1 lib/ouvrages_file_uploader.rb