1

I am using carrierwave and fog gem for uploading files to s3.

In my app user can select their own aws credentials for saving their files. so I cant use initializer. All the credentials will be saved on database with their user ID.

I have made a check in AvatarUplaoder to set the storage type.

     def self.call_set_storage_type
       active_type=UploadManagement.find_by_is_active(1)
       if active_type.nil?
        :file
       else
        if active_type.provider == "aws"
         :fog
        else 
         :file
        end
       end
    end
   storage call_set_storage_type

I want to make a method in ApplicationHelper or ApplicationController so that I can call it on AvatarUploader. I tried incuding application_helper in avatar_uploader but it didn't worked.

I want to make method in application_helper or applciation_controller because I need that method at many places and also I have other uploaders also to make code DRY I need to call but I am not able to think it.

I checked the documentation also different storage for each uplaoder

Please guide me how can I do that or any alternate solutions are also welcome.

thedudecodes
  • 1,479
  • 1
  • 16
  • 37
  • 1
    Why do you even want this in a helper? Wouldn't it make more sense to just place it in the needed class? If you need to use it multiple places then create your own module and include it as needed.Placing it in ApplicationHelper will cause the method to bleed through the application for no reason. – engineersmnky Sep 20 '17 at 12:56
  • @engineersmnky this makes sense and actually I did like this but still not able to upload files to s3. I made a module common_uploader.rb but . i want to fetch the credetials from db of the user but dont know how to do it – thedudecodes Sep 21 '17 at 05:29

0 Answers0