Sha256: 2f54b79a043ce206fcb77599e67274d40ba4ceec6815571f103a3168d38259e9

Contents?: true

Size: 649 Bytes

Versions: 22

Compression:

Stored size: 649 Bytes

Contents

require_dependency "my_forum/application_controller"

module MyForum
  class AttachmentsController < ApplicationController

    def create
      upload_path = File.join(Attachment::UPLOAD_PATH, current_user.id.to_s)

      # Create dir of not exists
      FileUtils::mkdir_p upload_path

      uploaded_io = params[:file]
      File.open(File.join(upload_path, uploaded_io.original_filename), 'wb') do |file|
        file.write(uploaded_io.read)
      end

      attachment = Attachment.create(user_id: current_user.id, file_name: uploaded_io.original_filename)

      render json: { success: true, attachment_id: attachment.id }
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
my_forum-0.0.1.beta25 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta24 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta23 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta22 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta21 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta20 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta19 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta18 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta17 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta16 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta15 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta14 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta13 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta12 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta11 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta10 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta9 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta8 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta7 app/controllers/my_forum/attachments_controller.rb
my_forum-0.0.1.beta5 app/controllers/my_forum/attachments_controller.rb