ruby on rails - How to upload to local storage? -


i have model method below, uploads aws s3 bucket in production. works. problem did same within development , testing environment (before added if...else statement). therefore, extend model method uploads local file storage when within development or testing environment.

but i'm not sure how add this. i've been following hartl's railstutorial , basic image uploading uses fog gem. uses uploader there, not apply situation. not sure if , how should use fog gem in situation. suggest code else part of model method below?

def self.upload_file(id)   if rails.env.production?     s3 = aws::s3::resource.new(            region: rails.application.secrets.aws_region,            credentials: aws::credentials.new(              rails.application.secrets.s3_access_key,              rails.application.secrets.s3_secret_key)           )     myfile = 'app/assets/emptyfile.xml'     filename = "myfiles/#{id}/file-#{id}.xml"     obj = s3.bucket(rails.application.secrets.s3_bucket_conceptmap).object(filename)     obj.upload_file(myfile)     conceptmap.create!(organization_id: id, myfile: obj.public_url)   else     ### same above local file storage instead of s3 bucket ###   end end 

compiling our comment conversation conclusion here others can take this:

you should create new uploader mentioned in tutorial following. move uploader related code new uploader modularize things. of code lying in self.upload_file(id) currently, meant in uploader.

it solve problem.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -