<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ruby on rails Archives | Clever Cloud</title>
	<atom:link href="https://www.clever.cloud/blog/tag/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.clever.cloud/blog/tag/ruby-on-rails/</link>
	<description>From Code to Product</description>
	<lastBuildDate>Thu, 28 May 2020 14:20:00 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://cdn.clever-cloud.com/uploads/2023/03/cropped-cropped-favicon-32x32.png</url>
	<title>ruby on rails Archives | Clever Cloud</title>
	<link>https://www.clever.cloud/blog/tag/ruby-on-rails/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Cellar a S3-like service for Rails&#8217; Active Storage</title>
		<link>https://www.clever.cloud/blog/engineering/2020/05/28/cellar-s3-active-storage-ruby-on-rails/</link>
		
		<dc:creator><![CDATA[Valeriane Venance]]></dc:creator>
		<pubDate>Thu, 28 May 2020 14:20:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[active storage]]></category>
		<category><![CDATA[cellar]]></category>
		<category><![CDATA[rails attachments]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2020/05/28/cellar-s3-active-storage-ruby-on-rails/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="railsbanner 1" decoding="async" fetchpriority="high" srcset="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Introduced with the release of Rails 5.2 , Active Storage replaces previous solutions for storing user videos, images, PDF, etc..</p>
<p>In the documentation only three implementations are demonstrated and they all rely on cloud services. Today I am going to show you how to use it to be Clever Cloud compatible.</p>
<span id="more-2827"></span>
<p>To follow this tutorial you must already have a Rails &gt;= 5.2 application running on Clever Cloud with a PostgreSQL database. You can <a href="https://www.clever.cloud/blog/engineering/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/">read this</a> if you need a basic setup.</p>
<h2 id="tell-rails-you-want-to-use-active-storage">Tell Rails you want to use Active Storage</h2>
<p>In your console, at the root of your rails project repository, type in <code>$ rails active_storage:install</code>. This will create two migration files under <code>./db/migrate</code>. These migrations will create two new tables: <code>active_storage_blobs</code> and <code>active_storage_attachments</code>, which is everything we need to start storing user attachments without adding new columns to our already existent models. Let&#39;s run them with <code>$ rake db:migrate</code> to have a local database up to date. You can now use <code>has_one_attached :&lt;the name you want to give&gt;</code> on any of your models to add an attachment on it.</p>
<h2 id="setting-up-the-application-for-clever-cloud">Setting up the application for Clever Cloud</h2>
<p>As we do provide AWS S3 like storage at Clever Cloud, we will use AWS gem and define custom endpoints. Add <code>gem &quot;aws-sdk-s3&quot;, require: false</code> to your Gemfile. Run <code>$ bundle install</code>. Then in <code>config/environments/production.yml</code> add <code>config.active_storage.service = :clevercloud</code>. Now in <code>config/storage.yml</code> add the following lines:</p>
<pre><code class="language-yaml">clevercloud:
  service: S3
  access_key_id: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_ID&#39;] %&gt;
  secret_access_key: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_SECRET&#39;] %&gt;
  region: us-east-1
  bucket: &lt;%= ENV[&#39;CELLAR_ADDON_BUCKET_NAME&#39;] %&gt;
  endpoint: &lt;%= ENV[&#39;CELLAR_ADDON_ENDPOINT&#39;] %&gt;
</code></pre>
<p>I must make clear here that we do not use regions at Clever Cloud, but the aws-sdk-s3 gem needs it; otherwise it throws an <code>AWS::Errors::MissingRegionError</code> error. And we do not want a 500 in production. It is the usage of <code>endpoint</code> that will give us the right endpoint generated by the gem.</p>
<h2 id="creating-our-storage-on-clever-cloud">Creating our storage on Clever Cloud</h2>
<p>Under the organization where your Rails application is deployed, select <strong>Create</strong>, <strong>an add-on</strong>, <strong>Cellar S3 storage</strong>. When prompted <strong>Select the applications that will use this add-on:</strong> select your Rails application. Name it and let it be deployed. Once this is done, in your <strong>addon dashboard</strong>, create a bucket. Keep its name. Now, under <strong>Environment variables</strong> in your Rails application, add the following:</p>
<pre><code class="language-bash">CELLAR_ADDON_BUCKET_NAME=&lt;your bucket name&gt;
CELLAR_ADDON_ENDPOINT=https://cellar-c2.services.clever-cloud.com
</code></pre>
<p>You can now commit the local files we have changed and push them to your Clever Cloud remote to enjoy Active Storage in production.</p>
<p>Do not forget to edit your safe params in your controllers, forms and permissions.</p>
<p>Happy storing!</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="railsbanner 1" decoding="async" srcset="https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/railsbanner-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Introduced with the release of Rails 5.2 , Active Storage replaces previous solutions for storing user videos, images, PDF, etc..</p>
<p>In the documentation only three implementations are demonstrated and they all rely on cloud services. Today I am going to show you how to use it to be Clever Cloud compatible.</p>
<span id="more-2827"></span>
<p>To follow this tutorial you must already have a Rails &gt;= 5.2 application running on Clever Cloud with a PostgreSQL database. You can <a href="https://www.clever.cloud/blog/engineering/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/">read this</a> if you need a basic setup.</p>
<h2 id="tell-rails-you-want-to-use-active-storage">Tell Rails you want to use Active Storage</h2>
<p>In your console, at the root of your rails project repository, type in <code>$ rails active_storage:install</code>. This will create two migration files under <code>./db/migrate</code>. These migrations will create two new tables: <code>active_storage_blobs</code> and <code>active_storage_attachments</code>, which is everything we need to start storing user attachments without adding new columns to our already existent models. Let&#39;s run them with <code>$ rake db:migrate</code> to have a local database up to date. You can now use <code>has_one_attached :&lt;the name you want to give&gt;</code> on any of your models to add an attachment on it.</p>
<h2 id="setting-up-the-application-for-clever-cloud">Setting up the application for Clever Cloud</h2>
<p>As we do provide AWS S3 like storage at Clever Cloud, we will use AWS gem and define custom endpoints. Add <code>gem &quot;aws-sdk-s3&quot;, require: false</code> to your Gemfile. Run <code>$ bundle install</code>. Then in <code>config/environments/production.yml</code> add <code>config.active_storage.service = :clevercloud</code>. Now in <code>config/storage.yml</code> add the following lines:</p>
<pre><code class="language-yaml">clevercloud:
  service: S3
  access_key_id: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_ID&#39;] %&gt;
  secret_access_key: &lt;%= ENV[&#39;CELLAR_ADDON_KEY_SECRET&#39;] %&gt;
  region: us-east-1
  bucket: &lt;%= ENV[&#39;CELLAR_ADDON_BUCKET_NAME&#39;] %&gt;
  endpoint: &lt;%= ENV[&#39;CELLAR_ADDON_ENDPOINT&#39;] %&gt;
</code></pre>
<p>I must make clear here that we do not use regions at Clever Cloud, but the aws-sdk-s3 gem needs it; otherwise it throws an <code>AWS::Errors::MissingRegionError</code> error. And we do not want a 500 in production. It is the usage of <code>endpoint</code> that will give us the right endpoint generated by the gem.</p>
<h2 id="creating-our-storage-on-clever-cloud">Creating our storage on Clever Cloud</h2>
<p>Under the organization where your Rails application is deployed, select <strong>Create</strong>, <strong>an add-on</strong>, <strong>Cellar S3 storage</strong>. When prompted <strong>Select the applications that will use this add-on:</strong> select your Rails application. Name it and let it be deployed. Once this is done, in your <strong>addon dashboard</strong>, create a bucket. Keep its name. Now, under <strong>Environment variables</strong> in your Rails application, add the following:</p>
<pre><code class="language-bash">CELLAR_ADDON_BUCKET_NAME=&lt;your bucket name&gt;
CELLAR_ADDON_ENDPOINT=https://cellar-c2.services.clever-cloud.com
</code></pre>
<p>You can now commit the local files we have changed and push them to your Clever Cloud remote to enjoy Active Storage in production.</p>
<p>Do not forget to edit your safe params in your controllers, forms and permissions.</p>
<p>Happy storing!</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
