@@ -25,6 +25,56 @@ nctl create application rails \
2525 --env=SECRET_KEY_BASE=$( rails secret)
2626```
2727
28+ ### Ruby On Rails with ActiveStorage
29+
30+ Next to the basic Rails example, we also provide a Rails application that has ActiveStorage configured with
31+ Deploio Object Storage.
32+
33+ Once deployed, you can head to the root page of the app and test the upload functionality. The example app supports
34+ direct uploads from the browser (CORS configuration is required as below) and custom bucket hostnames
35+ (DNS change required, see below).
36+
37+ ``` bash
38+ # setup postgres database
39+ nctl create postgresdatabase rails-active-storage-db --location=nine-es34 --wait
40+ DATABASE_URL=" $( nctl get postgresdatabase rails-active-storage-db --print-connection-string) "
41+
42+ # setup application
43+ nctl create application rails-active-storage \
44+ --git-url=https://github.com/ninech/deploio-examples \
45+ --git-sub-path=ruby/rails-active-storage \
46+ --env=SECRET_KEY_BASE=$( rails secret) \; DATABASE_URL=${DATABASE_URL}
47+
48+ # create bucket
49+ nctl create bucket --location=nine-es34 rails-active-storage-bucket
50+
51+ # create bucket user
52+ nctl create bucketuser --location=nine-es34 rails-active-storage-bucketuser
53+
54+ # grant bucket user read & write access to bucket
55+ nctl update bucket rails-active-storage-bucket --permissions reader=rails-active-storage-bucketuser \
56+ --permissions writer=rails-active-storage-bucketuser
57+
58+ # update application with object storage credentials
59+ ACCESS_KEY=" $( nctl get bucketuser rails-active-storage-bucketuser --print-credentials -o json | jq -r .s3_access_key) "
60+ SECRET_KEY=" $( nctl get bucketuser rails-active-storage-bucketuser --print-credentials -o json | jq -r .s3_secret_key) "
61+ nctl update app rails-active-storage --env=" S3_ACCESS_KEY=${ACCESS_KEY} ;S3_SECRET_KEY=${SECRET_KEY} ;S3_ENDPOINT=https://es34.objects.nineapis.ch;S3_BUCKET=rails-active-storage-bucket"
62+
63+ # optional: custom bucket hostnames
64+ nctl update bucket rails-active-storage-bucket --custom-hostnames={S3_BUCKET_HOST}
65+ nctl update app rails-active-storage --env=" S3_BUCKET_HOST={S3_BUCKET_HOST}"
66+ nctl get bucket rails-active-storage-bucket --output=" yaml" # setup DNS
67+
68+ # CORS configuration for direct uploads from browser
69+ # see https://guides.rubyonrails.org/active_storage_overview.html#cross-origin-resource-sharing-cors-configuration
70+ APP_HOST=$( nctl get app rails-active-storage -o json | jq -r " .status.atProvider.defaultURLs | first" )
71+ nctl update bucket rails-active-storage-bucket \
72+ --cors origins=${APP_HOST} \
73+ --cors allowed-headers=Content-Type,Content-MD5,Content-Disposition \
74+ --cors response-headers=Content-Type,Content-MD5,Content-Disposition,ETag \
75+ --cors max-age=3600
76+ ```
77+
2878## Ruby - Sinatra on Falcon
2979
3080``` bash
0 commit comments