Rails 5.2 Active Storage with AWS (Local Development) - ruby-on-rails

I've set up AWS S3 to store my images on Rails 5.2 with active storage when in production mode. This is great however I've noticed if I copy down the database from Heroku to my local machine so that I can work on the current platform state I get missing images due to the virtual blob storage in active storage.
I've written some statements so that it just ignores the call and not give nil errors etc. My question is...
Should I set up my Rails app to store images to AWS S3 when in development and working in local? This doesn't seem right however I am unsure how I can just copy down the production database into my local machine and the images will appear too (active storage blob url will be correct). I'm guessing it's a config issue on the local side coupled up with active storage..... (Head scratching).
Has anyone else come across this? Thank you.

This is the way I've been using Active Storage:
I have two databases (one local for development and the other on Heroku for production) and two cloud storage buckets (dev/prod), so when I'm developing I'll be using the same cloud storage as in production, but each database is associated with each own bucket.
This way I can test in development the same conditions then production.
Hope this may help :-)

Related

Can Heroku be made to use a persistent filesystem?

I've built an app where users can upload their avatars. I used the paperclip gem and everything works fine on my local machine. On Heroku everything works fine until server restart. Then every uploaded images disappear. Is it possible to keep them on the server?
Notice: I probably should use services such as Amazon S3 or Google Cloud. However each of those services require credit card or banking account information, even if you want to use a free mode. This is a small app just for my portfolio and I would rather avoid sending that information.
No, this isn't possible. Heroku's filesystem is ephemeral and there is no way to make it persistent. You will lose your uploads every time your dyno restarts.
You must use an off-site file storage service like Amazon S3 if you want to store files long-term.
(Technically you could store your images directly in your database, e.g. as a bytea in Postgres, but I strongly advise against that. It's not very efficient and then you have to worry about how to provide the saved files to the browser. Go with S3 or something similar.)

Rails hosting for small photo app

I'm making a small photo-gallery app. The photos will be hosted locally. Right now I use dreamhost but their rails implementation looks horrible. So I'm looking for other options. I know Heroku gives you one 'web dyno' for free, but they don't say anything about how much space you get. As I said, I want my photos stored locally with the app, I don't want to deal with s3 or other cloud storage.
there is no local storage with heroku - only temporary space. you'll need to use S3 or some off-site storage with heroku.
(and I agree, rails on DH is awful, even if you enable passenger)
Use Openshift to deploy your app
checkout this deploying rails app in openshift
openshift provides one permanent data directory to store data and its free
If you are interested in VPS, Digital Ocean - https://www.digitalocean.com/, provides excellent hosting starting from $5. And you can store your photos on the local disc.
There are very good tutorials on their site to get you started with.
Check out Shelly Cloud: https://shellycloud.com/ You get persistent storage (so you don't lose data in case of disk failure) and the deployment is optimized for Rails applications.
With Heroku you can host images that you store in the repository of your project. Just try this:
rails new mytest
create a simple page and link to a test image in your /app/assets/images
heroku create mytest123 # <-- mytest1234 must be your unique app name
and now push the repo to Heroku:
git push origin master # origin points automatically to Heroku after you created this
This is the easiest way to host small projects for free. Sometimes the Dyno takes some time to startup, and you need to point the domain to the right proxy, but these issues can be dealt with later.
S3 comes into play when you deal with uploaded content / images. For this use case, you need S3 which is out of the scope of your question too.

Rails - How to store uploads on my database server

In my Rails app, for HIPAA reasons, I need to keep all my data stored on a separate server from my web application. This is simple to do with the database, but what's the best way to allow my rails app (on the web server) to access uploads on the filesystem of the database server? Or should I just store the uploads in the database (mysql)?
I'm using Rails 3.2 and Paperclip, but could switch to Carrierwave or another solution
Thanks!
Or should I just store the uploads in the database (mysql)
No. I will point you here for a better explanation Storing Images in DB - Yea or Nay?
what's the best way to allow my rails app (on the web server) to access uploads on the filesystem of the database server
I would probably create another web server with a separate rails app that was responsible solely for serving up files from it's local filesystem through some authenticated API.
It looks like people do use Amazon S3 successfully with HIPAA-compliant websites for file storage.
Can you create a HIPAA compliant Amazon S3 Web Application?
Amazon White Paper - Creating HIPAA-compliant Medical Data Applications with AWS
Googling "amazon hipaa compliance" turns up quite a bit of info. I would look into this before building my own infrastructure for storing files.
you can configure paper clip to store your documents on amazon s3
https://github.com/thoughtbot/paperclip#storage
http://rubydoc.info/gems/paperclip/Paperclip/Storage/S3

How to disable database connection for local development?

I'm currently developing my Rails app on my local machine. I have no DB installed on my local machine, and I'm sending my codes to remote testing server which actually runs the app in development mode.
Until yesterday all commands like rails g model foo or rails g controller foo on my local machine worked with no errors.
But now all of rails generate commands started to fail due to no database connections. I think the direct reason is because I made some changes to my app configs, but I'm not sure where the changes are.
I guess the wrong part is that rails generate commands are always invoking active_record
which always verifies the DB connection.
Now, my question is:
Is there any way to temporally disable rails to verify the database connections, for local development(which has no DB connection available)?
I tried removing config/database.yml but it didn't help.
Your local development environment needs to have the same sort of facilities as the application requires. If you have database backed models then you need a database, preferably the same one as used when deploying the application so your tests are useful.
It really shouldn't be a big deal to set up a database for local development. Depending on your platform there are usually many different easy to use installers available.
Uploading your code changes to a remote server for execution is a really dysfunctional development model. If you have no alternative, it might be best to create the models on the remote system and pull them down to edit.

Rails Heroku Paperclip Files disapperad

I'm developing a webapp with Rails, Paperclip and Heroku but since my last commit were I just added Google Analytics the most of the uploaded images disappeared! That's my link: http://wo42.herokuapp.com/ I don't know why that happened oO
Heroku never used to let you write to their file-system although they have recently introduced something calld the ephemeral file-system - this article explains it. Best option is to use S3.
The actual issue here is that when you push to Heroku your application is re-deployed, and that won't be to the same machine that you were on before (it could be anywhere at any time).
Therefore, if you were uploading images to your local dynos filesystem, only that dyno had access to those files. When you deployed, that dyno would have been destroyed and a new one created.
This is why Heroku recommend that you use a persistent backing service such as S3 to store your uploaded and persisted files. This sort of service is available to all dynos and persists across deploys.
https://devcenter.heroku.com/articles/s3

Resources