<?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 Archives | Clever Cloud</title>
	<atom:link href="https://www.clever.cloud/blog/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.clever.cloud/blog/tag/ruby/</link>
	<description>From Code to Product</description>
	<lastBuildDate>Fri, 24 Oct 2025 12:50:38 +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 Archives | Clever Cloud</title>
	<link>https://www.clever.cloud/blog/tag/ruby/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Integrate Metabase in Ruby on Rails</title>
		<link>https://www.clever.cloud/blog/engineering/2020/05/14/metabase-integration-ruby-rails/</link>
		
		<dc:creator><![CDATA[Valeriane Venance]]></dc:creator>
		<pubDate>Thu, 14 May 2020 14:46:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[dashboard]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[metabase]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2020/05/14/metabase-integration-ruby-rails/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="metabasebanner 1" decoding="async" fetchpriority="high" srcset="https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Today, I am  proposing a very simple tutorial. I needed to integrate a Metabase dashboard in one of my applications and I realized there is no article which explains how to do that. So, ta-da!</p>
<span id="more-2825"></span>

<h2 id="requirements">Requirements</h2>
<p>To follow this tutorial, you will need</p>
<ul>
<li>a Metabase dashboard (read <a href="https://www.clever.cloud/blog/engineering/2019/02/20/how-to-install-metabase/">this article</a> from my fellow Laurent Dogin to have yours set up in a few minutes)</li>
<li>a Ruby on Rails application (read <a href="https://www.clever.cloud/blog/engineering/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/">this article</a> by me if you need to set up one)</li>
</ul>
<h2 id="enabling-integration-in-metabase">Enabling integration in Metabase</h2>
<p>From your Metabase, click on the top right <strong>gear icon</strong>, then <strong>Admin</strong>. On the left menu select <strong>Embedding in other Applications</strong>. Toggle the button to have it saying <strong>Enabled</strong>. You will now get an Embedding API key. Save it for later.</p>
<figure style="position:relative;width:100%;height:auto;margin:0 auto">
  <img data-action="zoom"  alt="Enable integrations on Metabase" src="https://cdn.clever-cloud.com/uploads/2021/08/metabase-integration-screenshot.png"/>
</figure>

<p>Leave Metabase admin and select the dashboard you want to integrate. Click the sharing and embedding icon on the top right of your dashboard. Now select <strong>Embed this dashboard in an Application</strong>. Finally, click on the <strong>Publish</strong> button.</p>
<h2 id="integrate-metabase-in-rails">Integrate Metabase in Rails</h2>
<p>In your Gemfile, add <code>gem &#39;jwt&#39;</code> then run <code>$ bundle install</code>. If your application is deployed on Clever Cloud go to your application&#39;s console and under your application&#39;s menu go to the <strong>environment variables</strong> menu. If you deploy locally, use the <a href="https://github.com/laserlemon/figaro">gem figaro</a> and edit your application.yml. Anyway you must add two environment variables</p>
<pre><code class="language-yaml">METABASE_SITE_URL: &lt;your metabase url&gt;
METABASE_SECRET_KEY: &lt;the API key from metabase admin&gt;
</code></pre>
<p>In the controller action where you want to integrate your metabase dashboard, add the following lines:</p>
<pre><code class="language-ruby">payload = {
          :resource =&gt; {:dashboard =&gt; &lt;your dashboard number&gt;},
          :params =&gt; { },
          :exp =&gt; Time.now.to_i + (60 * 10) # 10 minute expiration
    }
token = JWT.encode(payload, ENV[&quot;METABASE_SECRET_KEY&quot;])
@iframe_url = ENV[&quot;METABASE_SITE_URL&quot;] + &quot;/embed/dashboard/&quot; + token + &quot;#bordered=true&amp;titled=true&quot;
</code></pre>
<p>Now in your view, add</p>
<pre><code class="language-html">&lt;iframe
    src=&quot;&lt;%= @iframe_url %&gt;&quot;
    frameborder=&quot;0&quot;
    width=&quot;800&quot;
    height=&quot;600&quot;
    allowtransparency
&gt;&lt;/iframe&gt;
</code></pre>
<p>You are all set. Just restart your application so the new environment variables are taken in consideration. Voilà, your application now has an integrated Metabase dashboard.</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="metabasebanner 1" decoding="async" srcset="https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/metabasebanner-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Today, I am  proposing a very simple tutorial. I needed to integrate a Metabase dashboard in one of my applications and I realized there is no article which explains how to do that. So, ta-da!</p>
<span id="more-2825"></span>

<h2 id="requirements">Requirements</h2>
<p>To follow this tutorial, you will need</p>
<ul>
<li>a Metabase dashboard (read <a href="https://www.clever.cloud/blog/engineering/2019/02/20/how-to-install-metabase/">this article</a> from my fellow Laurent Dogin to have yours set up in a few minutes)</li>
<li>a Ruby on Rails application (read <a href="https://www.clever.cloud/blog/engineering/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/">this article</a> by me if you need to set up one)</li>
</ul>
<h2 id="enabling-integration-in-metabase">Enabling integration in Metabase</h2>
<p>From your Metabase, click on the top right <strong>gear icon</strong>, then <strong>Admin</strong>. On the left menu select <strong>Embedding in other Applications</strong>. Toggle the button to have it saying <strong>Enabled</strong>. You will now get an Embedding API key. Save it for later.</p>
<figure style="position:relative;width:100%;height:auto;margin:0 auto">
  <img data-action="zoom"  alt="Enable integrations on Metabase" src="https://cdn.clever-cloud.com/uploads/2021/08/metabase-integration-screenshot.png"/>
</figure>

<p>Leave Metabase admin and select the dashboard you want to integrate. Click the sharing and embedding icon on the top right of your dashboard. Now select <strong>Embed this dashboard in an Application</strong>. Finally, click on the <strong>Publish</strong> button.</p>
<h2 id="integrate-metabase-in-rails">Integrate Metabase in Rails</h2>
<p>In your Gemfile, add <code>gem &#39;jwt&#39;</code> then run <code>$ bundle install</code>. If your application is deployed on Clever Cloud go to your application&#39;s console and under your application&#39;s menu go to the <strong>environment variables</strong> menu. If you deploy locally, use the <a href="https://github.com/laserlemon/figaro">gem figaro</a> and edit your application.yml. Anyway you must add two environment variables</p>
<pre><code class="language-yaml">METABASE_SITE_URL: &lt;your metabase url&gt;
METABASE_SECRET_KEY: &lt;the API key from metabase admin&gt;
</code></pre>
<p>In the controller action where you want to integrate your metabase dashboard, add the following lines:</p>
<pre><code class="language-ruby">payload = {
          :resource =&gt; {:dashboard =&gt; &lt;your dashboard number&gt;},
          :params =&gt; { },
          :exp =&gt; Time.now.to_i + (60 * 10) # 10 minute expiration
    }
token = JWT.encode(payload, ENV[&quot;METABASE_SECRET_KEY&quot;])
@iframe_url = ENV[&quot;METABASE_SITE_URL&quot;] + &quot;/embed/dashboard/&quot; + token + &quot;#bordered=true&amp;titled=true&quot;
</code></pre>
<p>Now in your view, add</p>
<pre><code class="language-html">&lt;iframe
    src=&quot;&lt;%= @iframe_url %&gt;&quot;
    frameborder=&quot;0&quot;
    width=&quot;800&quot;
    height=&quot;600&quot;
    allowtransparency
&gt;&lt;/iframe&gt;
</code></pre>
<p>You are all set. Just restart your application so the new environment variables are taken in consideration. Voilà, your application now has an integrated Metabase dashboard.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Events: Cloud, Rails and more</title>
		<link>https://www.clever.cloud/blog/company/2019/09/27/railsgirls/</link>
		
		<dc:creator><![CDATA[Clément Nivolle]]></dc:creator>
		<pubDate>Fri, 27 Sep 2019 16:11:00 +0000</pubDate>
				<category><![CDATA[Company]]></category>
		<category><![CDATA[Nantes]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[sponsoring]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2019/09/27/railsgirls/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="railsgirls 1" decoding="async" srcset="https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-1368x528.png 1368w" sizes="(max-width: 1400px) 100vw, 1400px" /></p><p>Last week, Clever Cloud was part of the <em>Rails Girls</em> event in Nantes. As a company, we think that being involved in tech communities and helping people to be introduced to tech is a good and important thing.</p>
<span id="more-2766"></span>

<h2 id="sponsoring-rails-girls">Sponsoring Rails Girls</h2>
<figure>
  <img alt="The Rails Girls event in Nantes, 2019 " src="https://cdn.clever-cloud.com/uploads/2021/08/rais-girls-nantes-2019.jpg"/>
</figure>

<p>Last week, we sponsored the latest edition of Rails Girls in Nantes. This series of events, occurring in multiple cities, aims to give tools and a community for women to understand tech and build their ideas.</p>
<p>The RG team is powered by Sarah and Guillaume, two dedicated organizers we would like to thanks for their enthusiasm!</p>
<figure>
  <img alt="The rails girls Nantes team" src="https://cdn.clever-cloud.com/uploads/2021/08/rails-girl-nantes-team.jpg"/>
  <figcaption>The awesome Rails Girls Nantes team of 2019!</figcaption>
</figure>

<h2 id="whats-next-with-clever-cloud">What&#39;s next with Clever Cloud</h2>
<p>Also, we have several events in the coming weeks. Here &#39;s a bunch of them:</p>
<ul>
<li>The Devfest Nantes will host three Clever Cloud speakers:<ul>
<li>Valeriane Venance: <a href="https://devfest.gdgnantes.com/sessions/authentication_authorization_starters_battle/">Authentication/Authorization Starters Battle</a></li>
<li>Quentin Adam: <a href="https://devfest.gdgnantes.com/sessions/apache_pulsar_101__architecture__concepts_et_comparaison/">Apache Pulsar 101: architecture, concepts &amp; comparaison</a> with Steven LeRoux</li>
<li>Hubert Sablonnière: <a href="https://devfest.gdgnantes.com/sessions/le_web__ses_frameworks_et_ses_standards___deconstruire_pour_mieux__re__construire/">The Web, its frameworks and standards</a></li>
</ul>
</li>
<li><a href="https://voxxeddays.com/microservices/">Voxxed Microservices</a>: We&#39;ll be sponsoring the event, so feel free to see us at our booth !</li>
</ul>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="railsgirls 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/railsgirls-1-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><p>Last week, Clever Cloud was part of the <em>Rails Girls</em> event in Nantes. As a company, we think that being involved in tech communities and helping people to be introduced to tech is a good and important thing.</p>
<span id="more-2766"></span>

<h2 id="sponsoring-rails-girls">Sponsoring Rails Girls</h2>
<figure>
  <img alt="The Rails Girls event in Nantes, 2019 " src="https://cdn.clever-cloud.com/uploads/2021/08/rais-girls-nantes-2019.jpg"/>
</figure>

<p>Last week, we sponsored the latest edition of Rails Girls in Nantes. This series of events, occurring in multiple cities, aims to give tools and a community for women to understand tech and build their ideas.</p>
<p>The RG team is powered by Sarah and Guillaume, two dedicated organizers we would like to thanks for their enthusiasm!</p>
<figure>
  <img alt="The rails girls Nantes team" src="https://cdn.clever-cloud.com/uploads/2021/08/rails-girl-nantes-team.jpg"/>
  <figcaption>The awesome Rails Girls Nantes team of 2019!</figcaption>
</figure>

<h2 id="whats-next-with-clever-cloud">What&#39;s next with Clever Cloud</h2>
<p>Also, we have several events in the coming weeks. Here &#39;s a bunch of them:</p>
<ul>
<li>The Devfest Nantes will host three Clever Cloud speakers:<ul>
<li>Valeriane Venance: <a href="https://devfest.gdgnantes.com/sessions/authentication_authorization_starters_battle/">Authentication/Authorization Starters Battle</a></li>
<li>Quentin Adam: <a href="https://devfest.gdgnantes.com/sessions/apache_pulsar_101__architecture__concepts_et_comparaison/">Apache Pulsar 101: architecture, concepts &amp; comparaison</a> with Steven LeRoux</li>
<li>Hubert Sablonnière: <a href="https://devfest.gdgnantes.com/sessions/le_web__ses_frameworks_et_ses_standards___deconstruire_pour_mieux__re__construire/">The Web, its frameworks and standards</a></li>
</ul>
</li>
<li><a href="https://voxxeddays.com/microservices/">Voxxed Microservices</a>: We&#39;ll be sponsoring the event, so feel free to see us at our booth !</li>
</ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Clean up your Rails Controllers with Service Objects</title>
		<link>https://www.clever.cloud/blog/engineering/2019/06/14/clean-controllers-service-object-rails/</link>
		
		<dc:creator><![CDATA[Valeriane Venance]]></dc:creator>
		<pubDate>Fri, 14 Jun 2019 14:35:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[design pattern]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[separation of concerns]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2019/06/14/clean-controllers-service-object-rails/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="banner service objects 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><h2 id="fat-models-and-skinny-controllers-right">Fat Models and skinny Controllers right?</h2>
<p>You know what they say about the MVC design pattern, keep your Controllers light.<br>So at the beginning of your project, you added oil and gears to your Models and it was rolling just fine. Even if I&#39;m not a big fan of the big Model that even makes coffee (sending an email, really?), I can say that you were in perfect harmony with the framework principles.<br>Well, a few iterations later, this idyllic codebase seems very far away and your Controllers and Models are way more &#39;200 line&#39;ish than they used to be.</p>
<span id="more-2821"></span>

<p>Service Objects is a good solution to extract some logic out of them by transferring code into simple services that handles only one thing. This way, you end up with maintainable, super understandable and separated critical code.<br>On this article I&#39;m focusing on Controllers, but the principles are the same for Models. Now, some may ask, why not using Controller Helpers instead?</p>
<p>My answer to that would be: don&#39;t choose, use both!</p>
<h2 id="service-object-and-controller-helper">Service object and Controller helper</h2>
<p>Controller Helpers do hold code shared between Controllers and are also a good way to keep slim Controllers. They are great to respect the DRY (Don&#39;t Repeat Yourself) principles. If you target the same workflows in many Controllers, you must consider putting this logic into a helper. The code you put here is a simple succession of actions you do and conditions you are evaluating. They are useful only if used by at least two Controllers, otherwise, you should think of some code refactoring.<br>Anyway, we often hear that backend logic should not belong to the Controller and just moving everything into a helper won&#39;t solve the problem.</p>
<p>For every operation tied to your business logic (calling an API, calculation) performed in this duplicated code or present in any Controller, you should definitely consider creating a service object for each chunk of logic.</p>
<p>Okay, now you know when to use a service object, but what is it exactly?</p>
<figure>
  <img style="width:50%;margin-left:25%" alt="A League of Legends poro" src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/048fa9cc-2f1d-4920-b29d-c80d7aafb488/d63wx6c-8af07a43-f112-489d-9087-e9c10077b7c8.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzA0OGZhOWNjLTJmMWQtNDkyMC1iMjlkLWM4MGQ3YWFmYjQ4OFwvZDYzd3g2Yy04YWYwN2E0My1mMTEyLTQ4OWQtOTA4Ny1lOWMxMDA3N2I3YzgucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.5MEQgeD-7_FV8NIh-rv8j8gw6FYgyQBuG_eOVUHq0Rc"/>
  <figcaption>A fluffy poro ! - Art by justduet on DeviantArt</figcaption>
</figure>

<p>A service object is a PORO. No, not that cute fluffy League of Legends NPC, but a Plain Old Ruby Object.<br>You just create a class not related to ActiveRecord (the RubyOnRails ORM) with it&#39;s own methods, put your code there, and WOW, you now have a PORO!<br>We will see how we construct it later, first we need to know where to put it in our project.</p>
<h2 id="break-it-to-rebuild-it">Break it to rebuild it</h2>
<p>First, let&#39;s take this Controller. One thing we can notice is an API call in this <code>get_weather</code> method and this should not be Controller business.</p>
<pre><code class="language-ruby">class HomeController &lt; ApplicationController
    require &#39;curb&#39;
    def index
    end

    def get_weather
        http = Curl.get(&quot;#{ENV[&quot;api_base&quot;]}#{ENV[&quot;api_key&quot;]}&quot;)
        if http.status = &quot;200 OK&quot;
            response_body = JSON.parse http.body_str
            @current_weather = response_body[&quot;weather&quot;][0][&quot;description&quot;]
            @current_temperature = &quot;#{(response_body[&quot;main&quot;][&quot;temp&quot;].to_f - 273.15).round(1)} °C&quot;
        else
            @current_weather = &quot;There was an error sorry: #{current_weather[:error]}&quot;
        end
    end
end
</code></pre>
<p>According to the name of the design pattern, we will create a <code>services</code> folder at <code>root_path/app/services/</code>.<br>Okay, looks like it&#39;s about getting weather informations so we will name another folder accordingly.<br>Finally, we can create our service object file. For this, we will be the most explicit and we will use something like <em>x_service.rb</em>.</p>
<p>Being precise on naming and using the <code>_service</code> suffix is here to help other code maintainers to easily understand what is the purpose of the service and where to find it in the project.</p>
<h3 id="skeleton">Skeleton</h3>
<p>This is how we should start every new service object. Here, we can note the import of the library &quot;ostruct&quot;. This allows us to use the OpenStruct object in order to return a rich object containing error messages and a <code>success?</code> method.</p>
<pre><code class="language-ruby">class FolderName::NameOfTheService
    require &quot;ostruct&quot;
    
    def initialize(params={})
        @params = params
    end

    def call
        begin
        rescue =&gt; exception
            OpenStruct.new(success?: false,
                           error: exception.message)
        else
            OpenStruct.new(success?: true, 
                           error: nil)
        end
    end

end
</code></pre>
<h3 id="filling-it-up">Filling it up</h3>
<p>Instead of just copying our Controller&#39;s code into our private method, we will use the wide known begin/rescue pattern to manage errors and will use it at our advantage to raise our own errors.  </p>
<pre><code class="language-ruby">class Weather::GetCurrentWeatherService
  require &quot;ostruct&quot;

    def initialize(params={})
      @params = params
    end

    def call
      @api_base = ENV[&quot;api_base&quot;]
      @api_key = ENV[&quot;api_key&quot;]

      begin
        http = Curl.get(&quot;#{@api_base}#{@api_key}&quot;)
        if http.status == &quot;200 OK&quot;
          response_body = JSON.parse http.body_str
          if response_body[&quot;weather&quot;] &amp;&amp; response_body[&quot;main&quot;]
            weather_string = response_body[&quot;weather&quot;][0][&quot;description&quot;]
            temperature = &quot;#{(response_body[&quot;main&quot;][&quot;temp&quot;].to_f - 273.15).round(1)} °C&quot;
          else
            raise
          end
        else
          raise
        end
      rescue =&gt; exception
          OpenStruct.new(success?: false,
                 error: exception.message)
        else
          OpenStruct.new(success?: true, 
                 weather_string: weather_string, 
                 temperature: temperature, 
                 error: nil)
        end
    end

end
</code></pre>
<h3 id="lets-refactor-this-controller">Let&#39;s refactor this Controller</h3>
<pre><code class="language-ruby">def get_weather
    current_weather = ::Weather::GetCurrentWeatherService.new.call(params: {})
    if current_weather.success?
        @current_weather = current_weather[:weather_string]
        @current_temperature = current_weather[:temperature]
    else
        @current_weather = &quot;There was an error sorry: #{current_weather[:error]}&quot;
    end
end
</code></pre>
<p>We simply call a new instance of our service in our Controller and use it&#39;s <code>success?</code> method to handle regular Controller rendering logic. Note the use of the prepending <code>::</code> it&#39;s for preventing the Controller to look for the service only in its own repository.<br>Here, the params argument is just an empty hash that I do not use but this was to show that, like every PORO, a service can take many parameters.</p>
<h2 id="this-pattern-is-so-great-but-ive-made-a-mess">This pattern is so great, but I&#39;ve made a mess!</h2>
<p>If our weather service was real, we would probably want to handle city search, forecast weather and so on. Maybe we would have extended our service object or created a bunch of others and now it&#39;s an obscure code to maintain and you can feel like you&#39;re drowning. No worries, it&#39;s just time for you to be rescued by NameSpacing!</p>
<p>In fact we already used it by putting our service in a weather folder in the first place. You should definitely classify all your new services by folders and never hesitate to create a sub folder when your folder holds too many service files.<br>If your services can be sliced by fields of usage or are really tied to a Model or Controller, create new folders and move your services under the corresponding ones.</p>
<p>For naming your folders, no master rule, but logic, efficiency, and consistency between the names.<br>Of course, you will need to rename your services. For instance, under a folder named <code>my_folder/my_folder_2</code> your <code>my_service</code> will be renamed <code>MyFolder::MyFolder2::MyService</code> and you will now use the same name in your Controllers to use them.</p>
<h2 id="so-so-or-not">So, SO or not?</h2>
<p>As you may have notice, I was mostly giving advices on how to implement it and never refer to the official documentation.<br>This is because this pattern does not have any convention and everyone can implement it its own way. In order to avoid maintainability issues, I would really recommend keeping these concerns in mind:</p>
<ul>
<li>always think concerns separation.</li>
<li>don&#39;t let your services grow big.</li>
<li>always return rich objects.</li>
<li>all your return objects should have the same structure.</li>
</ul>
<p>Happy refactoring!</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="banner service objects 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/banner-service-objects-1-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><h2 id="fat-models-and-skinny-controllers-right">Fat Models and skinny Controllers right?</h2>
<p>You know what they say about the MVC design pattern, keep your Controllers light.<br>So at the beginning of your project, you added oil and gears to your Models and it was rolling just fine. Even if I&#39;m not a big fan of the big Model that even makes coffee (sending an email, really?), I can say that you were in perfect harmony with the framework principles.<br>Well, a few iterations later, this idyllic codebase seems very far away and your Controllers and Models are way more &#39;200 line&#39;ish than they used to be.</p>
<span id="more-2821"></span>

<p>Service Objects is a good solution to extract some logic out of them by transferring code into simple services that handles only one thing. This way, you end up with maintainable, super understandable and separated critical code.<br>On this article I&#39;m focusing on Controllers, but the principles are the same for Models. Now, some may ask, why not using Controller Helpers instead?</p>
<p>My answer to that would be: don&#39;t choose, use both!</p>
<h2 id="service-object-and-controller-helper">Service object and Controller helper</h2>
<p>Controller Helpers do hold code shared between Controllers and are also a good way to keep slim Controllers. They are great to respect the DRY (Don&#39;t Repeat Yourself) principles. If you target the same workflows in many Controllers, you must consider putting this logic into a helper. The code you put here is a simple succession of actions you do and conditions you are evaluating. They are useful only if used by at least two Controllers, otherwise, you should think of some code refactoring.<br>Anyway, we often hear that backend logic should not belong to the Controller and just moving everything into a helper won&#39;t solve the problem.</p>
<p>For every operation tied to your business logic (calling an API, calculation) performed in this duplicated code or present in any Controller, you should definitely consider creating a service object for each chunk of logic.</p>
<p>Okay, now you know when to use a service object, but what is it exactly?</p>
<figure>
  <img style="width:50%;margin-left:25%" alt="A League of Legends poro" src="https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/048fa9cc-2f1d-4920-b29d-c80d7aafb488/d63wx6c-8af07a43-f112-489d-9087-e9c10077b7c8.png?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcLzA0OGZhOWNjLTJmMWQtNDkyMC1iMjlkLWM4MGQ3YWFmYjQ4OFwvZDYzd3g2Yy04YWYwN2E0My1mMTEyLTQ4OWQtOTA4Ny1lOWMxMDA3N2I3YzgucG5nIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.5MEQgeD-7_FV8NIh-rv8j8gw6FYgyQBuG_eOVUHq0Rc"/>
  <figcaption>A fluffy poro ! - Art by justduet on DeviantArt</figcaption>
</figure>

<p>A service object is a PORO. No, not that cute fluffy League of Legends NPC, but a Plain Old Ruby Object.<br>You just create a class not related to ActiveRecord (the RubyOnRails ORM) with it&#39;s own methods, put your code there, and WOW, you now have a PORO!<br>We will see how we construct it later, first we need to know where to put it in our project.</p>
<h2 id="break-it-to-rebuild-it">Break it to rebuild it</h2>
<p>First, let&#39;s take this Controller. One thing we can notice is an API call in this <code>get_weather</code> method and this should not be Controller business.</p>
<pre><code class="language-ruby">class HomeController &lt; ApplicationController
    require &#39;curb&#39;
    def index
    end

    def get_weather
        http = Curl.get(&quot;#{ENV[&quot;api_base&quot;]}#{ENV[&quot;api_key&quot;]}&quot;)
        if http.status = &quot;200 OK&quot;
            response_body = JSON.parse http.body_str
            @current_weather = response_body[&quot;weather&quot;][0][&quot;description&quot;]
            @current_temperature = &quot;#{(response_body[&quot;main&quot;][&quot;temp&quot;].to_f - 273.15).round(1)} °C&quot;
        else
            @current_weather = &quot;There was an error sorry: #{current_weather[:error]}&quot;
        end
    end
end
</code></pre>
<p>According to the name of the design pattern, we will create a <code>services</code> folder at <code>root_path/app/services/</code>.<br>Okay, looks like it&#39;s about getting weather informations so we will name another folder accordingly.<br>Finally, we can create our service object file. For this, we will be the most explicit and we will use something like <em>x_service.rb</em>.</p>
<p>Being precise on naming and using the <code>_service</code> suffix is here to help other code maintainers to easily understand what is the purpose of the service and where to find it in the project.</p>
<h3 id="skeleton">Skeleton</h3>
<p>This is how we should start every new service object. Here, we can note the import of the library &quot;ostruct&quot;. This allows us to use the OpenStruct object in order to return a rich object containing error messages and a <code>success?</code> method.</p>
<pre><code class="language-ruby">class FolderName::NameOfTheService
    require &quot;ostruct&quot;
    
    def initialize(params={})
        @params = params
    end

    def call
        begin
        rescue =&gt; exception
            OpenStruct.new(success?: false,
                           error: exception.message)
        else
            OpenStruct.new(success?: true, 
                           error: nil)
        end
    end

end
</code></pre>
<h3 id="filling-it-up">Filling it up</h3>
<p>Instead of just copying our Controller&#39;s code into our private method, we will use the wide known begin/rescue pattern to manage errors and will use it at our advantage to raise our own errors.  </p>
<pre><code class="language-ruby">class Weather::GetCurrentWeatherService
  require &quot;ostruct&quot;

    def initialize(params={})
      @params = params
    end

    def call
      @api_base = ENV[&quot;api_base&quot;]
      @api_key = ENV[&quot;api_key&quot;]

      begin
        http = Curl.get(&quot;#{@api_base}#{@api_key}&quot;)
        if http.status == &quot;200 OK&quot;
          response_body = JSON.parse http.body_str
          if response_body[&quot;weather&quot;] &amp;&amp; response_body[&quot;main&quot;]
            weather_string = response_body[&quot;weather&quot;][0][&quot;description&quot;]
            temperature = &quot;#{(response_body[&quot;main&quot;][&quot;temp&quot;].to_f - 273.15).round(1)} °C&quot;
          else
            raise
          end
        else
          raise
        end
      rescue =&gt; exception
          OpenStruct.new(success?: false,
                 error: exception.message)
        else
          OpenStruct.new(success?: true, 
                 weather_string: weather_string, 
                 temperature: temperature, 
                 error: nil)
        end
    end

end
</code></pre>
<h3 id="lets-refactor-this-controller">Let&#39;s refactor this Controller</h3>
<pre><code class="language-ruby">def get_weather
    current_weather = ::Weather::GetCurrentWeatherService.new.call(params: {})
    if current_weather.success?
        @current_weather = current_weather[:weather_string]
        @current_temperature = current_weather[:temperature]
    else
        @current_weather = &quot;There was an error sorry: #{current_weather[:error]}&quot;
    end
end
</code></pre>
<p>We simply call a new instance of our service in our Controller and use it&#39;s <code>success?</code> method to handle regular Controller rendering logic. Note the use of the prepending <code>::</code> it&#39;s for preventing the Controller to look for the service only in its own repository.<br>Here, the params argument is just an empty hash that I do not use but this was to show that, like every PORO, a service can take many parameters.</p>
<h2 id="this-pattern-is-so-great-but-ive-made-a-mess">This pattern is so great, but I&#39;ve made a mess!</h2>
<p>If our weather service was real, we would probably want to handle city search, forecast weather and so on. Maybe we would have extended our service object or created a bunch of others and now it&#39;s an obscure code to maintain and you can feel like you&#39;re drowning. No worries, it&#39;s just time for you to be rescued by NameSpacing!</p>
<p>In fact we already used it by putting our service in a weather folder in the first place. You should definitely classify all your new services by folders and never hesitate to create a sub folder when your folder holds too many service files.<br>If your services can be sliced by fields of usage or are really tied to a Model or Controller, create new folders and move your services under the corresponding ones.</p>
<p>For naming your folders, no master rule, but logic, efficiency, and consistency between the names.<br>Of course, you will need to rename your services. For instance, under a folder named <code>my_folder/my_folder_2</code> your <code>my_service</code> will be renamed <code>MyFolder::MyFolder2::MyService</code> and you will now use the same name in your Controllers to use them.</p>
<h2 id="so-so-or-not">So, SO or not?</h2>
<p>As you may have notice, I was mostly giving advices on how to implement it and never refer to the official documentation.<br>This is because this pattern does not have any convention and everyone can implement it its own way. In order to avoid maintainability issues, I would really recommend keeping these concerns in mind:</p>
<ul>
<li>always think concerns separation.</li>
<li>don&#39;t let your services grow big.</li>
<li>always return rich objects.</li>
<li>all your return objects should have the same structure.</li>
</ul>
<p>Happy refactoring!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Setup your Ruby on Rails Online Dev Environment</title>
		<link>https://www.clever.cloud/blog/engineering/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/</link>
		
		<dc:creator><![CDATA[Valeriane Venance]]></dc:creator>
		<pubDate>Tue, 07 May 2019 13:35:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[dev env]]></category>
		<category><![CDATA[preprod]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2019/05/07/setup-your-ruby-on-rails-online-dev-environment/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="clevercloud dev env ror" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p>In this tutorial we are going to install the latest version of RubyOnRails and deploy it on Clever Cloud to use it as a development environment.

<span id="more-2820"></span>
<h2 id="prerequisites">Prerequisites</h2>
This article presumes you already are a RubyOnRails developer. If you are not and want to learn RubyOnRails, <a href="https://guides.rubyonrails.org/getting_started.html">start here</a> with the official documentation.

From the technical point of view, I presume you already have an installed ruby version &gt;= 2.5.0 and a version of rubygems &gt;= 1.8.11.

I also assume you know what Clever Cloud is. If you don't you maybe want to read <a href="https://www.clever.cloud/en/">this</a> first.
<h2 id="rails-local-installation">Rails local installation</h2>
In your favorite terminal type <code>$ gem install rails --pre</code>. Of course you can install any rails version you would like to use with <code>$ gem install rails -v X.X.X</code>.

After the installation logs, type in <code>$ rails new &lt;your_project_name&gt;</code> then <code>$ cd &lt;your_project_name&gt;</code>.

From now I will always assume your are currently located at this path in your terminal.
<h2 id="super-fast-version">Super fast version</h2>
If you prefer to read the docs, here is all you need:
<ul>
 	<li><a href="https://www.clever.cloud/developers/doc/applications/ruby/">Deploying ruby on rails application.</a></li>
 	<li><a href="https://www.clever.cloud/developers/addons/postgresql/">Docs for PostgreSQL add-on</a>.</li>
 	<li><a href="https://www.clever.cloud/developers/addons/fs_buckets/">Docs for FSBuckets filestystems</a>(optional).</li>
 	<li><a href="https://www.clever.cloud/developers/clever-tools/getting_started/">Docs for the clever-tools CLI</a>.</li>
</ul>
<h2 id="step-by-step-version">Step by step version</h2>
<h2 id="get-your-app-ready-for-production">Get your app ready for production</h2>
<h3 id="database-settings">Database settings</h3>
With your favorite text editor open <code>./config/database.yml</code>. Replace the generated content at <code>default: &amp;default</code> with
<pre><code class="language-yaml">default: &amp;default
  adapter: postgresql
  encoding: unicode
  timeout: 5000
</code></pre>
do the same with what's under <code>production:</code> with
<pre><code class="language-yaml">production:
  &lt;&lt;: *default
  database: &lt;%= ENV['POSTGRESQL_ADDON_DB'] %&gt;
  username: &lt;%= ENV['POSTGRESQL_ADDON_USER'] %&gt;
  password: &lt;%= ENV['POSTGRESQL_ADDON_PASSWORD'] %&gt;
  host: &lt;%= ENV['POSTGRESQL_ADDON_HOST'] %&gt;
  port: &lt;%= ENV['POSTGRESQL_ADDON_PORT'] %&gt;
</code></pre>
Save the file.
<h3 id="dependencies-settings">Dependencies settings</h3>
Open <code>./Gemfile</code> with your text editor and replace
<pre><code class="language-bash"># Use sqlite3 as the database for Active Record
gem 'sqlite3', '~&gt; 1.4'
</code></pre>
with
<pre><code class="language-bash"># Use postgresql as the database for Active Record
gem 'pg'
</code></pre>
and save the file. Run <code>$ bundle install</code> to have <code>Gemfile.lock</code> updated.
<h3 id="deployment-orchestration-settings">Deployment orchestration settings</h3>
In your terminal create a new folder <code>$ mkdir clevercloud</code>

create a new file <code>$ touch clevercloud/ruby.json</code>.

Open the new file <code>./clevercloud/ruby.json</code> with a text editor and add the following
<pre><code class="language-json">{
  "deploy" : {
    "rakegoals": ["db:migrate", "assets:precompile"],
    "static": "/public"
  }
}
</code></pre>
Don't forget to commit your file and push it.
<h2 id="clever-cloud-configuration">Clever Cloud configuration</h2>
<h3 id="i-dont-have-an-account">I don't have an account</h3>
Simply sign up <a href="https://api.clever-cloud.com/v2/session/signup">here</a>. You will get an email for email address validation. Just click the link, you will be redirected to the Clever Cloud console with your free credits unlocked.

Jump to <strong>Creating the application</strong> section and skip the login part.
<h3 id="i-have-an-account">I have an account</h3>
Go to the <a href="https://console.clever-cloud.com/">Clever Cloud console</a> and log in.
<h3 id="creating-the-application">Creating the application</h3>
You are now logged in the Clever Cloud console. Under your organisation select <code>+ Create</code>, on the next screen click <code>Brand new app</code>.

Select the <code>Ruby</code> language, click <code>Edit</code> and select the CPU size you need. I would suggest for a dev environment you select the smallest one and scale when you need more resources. Finish editing this part with <code>Next</code>.

Name your application in the following screen, for next references to that name, I will use <code>&lt;your_application_name&gt;</code>. Add a little description if you want to. Select your deployment zone (where the code will be physically hosted) and finish this section with next.
<h3 id="database-setup">Database setup</h3>
On the next screen, scroll until you find <code>PostgreSQL</code> and select this add-on. Select the database size you need and click <code>Next</code> in the bottom right. Name your database and select the same location as the one you picked for your ruby application.
<h3 id="setting-environment-variables">Setting environment variables</h3>
In the following screen you see an interface to add additional environment variables. Don't change or erase those already set up, unless you know what you are doing and why you need to do so.
<h4 id="secret_key_base">SECRET_KEY_BASE</h4>
In your terminal generate a secret key with <code>$ rake secret</code>. Copy the key you obtained and paste it in the Clever Cloud console as an environment variable value under those already present. As a name, use <code>SECREY_KEY_BASE</code> and click <code>ADD</code>.
<h4 id="ruby_version">RUBY_VERSION</h4>
Check if a ruby version is specified with <code>$ cat ./Gemfile</code>. If so click <code>Next</code> and go straight to the next chapter.

If not use your ruby version manager to check the current version. E.g with <a href="https://rvm.io/">rvm</a>: <code>$ rvm current</code> Output: <code>$ ruby-2.6.0</code> So in the environment variables editor add <code>RUBY_VERSION</code> as name, and in this case <code>2.6.0</code> as value. Click <code>ADD</code>, then <code>Next</code>.
<h3 id="i-need-a-filesystem">I need a filesystem</h3>
Click on the left panel on <code>+ Create</code> and this time, select <code>an add-on</code>, and scroll until you find <code>FS Bucket</code>. Just click <code>Next</code> on the following screen. A list of your applications will be displayed. Link it with <code>&lt;your_application_name&gt;</code>. Select <code>Next</code> again, and now, name your Bucket and select the same deployment zone as for your application and database. <code>Next</code>.
<h2 id="deploying-the-application">Deploying the application!</h2>
We will use the <a href="https://github.com/CleverCloud/clever-tools">Clever Cloud CLI</a> for that.
<h3 id="the-clever-cloud-cli">The Clever Cloud CLI</h3>
most common installations:

<strong>npm</strong>: <code>$ npm install -g clever-tools</code>

<strong>brew</strong>: <code>$ brew install CleverCloud/homebrew-tap/clever-tools</code>

<strong>linux</strong>:
<pre><code class="language-bash">$ curl https://clever-tools.cellar.services.clever-cloud.com/releases/latest/clever-tools-latest_linux.tar.gz
$ tar xvzf clever-tools-latest_linux.tar.gz
$ cp clever-tools-latest_linux/clever ~/.local/bin/
</code></pre>
For extended informations, check out <a href="https://www.clever.cloud/developers/clever-tools/getting_started/">this guide</a>.

Once the CLI is installed, login with <code>$ clever login</code>. A browser page will open. Enter your Clever Cloud account's credentials and go back to your terminal.

Link your application with <code>$ clever link &lt;your_application_name&gt;</code>.

If for some reason you have <code>$ [ERROR] Application not found</code> as an output, in the Clever Cloud console go in <code>&lt;your_application_name&gt;</code> and select the <code>Information</code> menu.

Copy the value of <code>Application ID</code> and in your terminal now type <code>$ clever link &lt;the value of Application ID&gt;</code>.
<h4 id="i-have-a-filesystem-only-if-you-have-followed-i-need-a-filesystem">I have a filesystem (only if you have followed #I need a filesystem)</h4>
Go in the Clever Cloud console, and find the <code>Informations</code> page of the File System Bucket you previously created.

Copy the first environment variable displayed, it should look as follows:

<code>CC_FS_BUCKET=/some/empty/folder:bucket-your-bucket-id-fsbucket.services.clever-cloud.com</code>.

Split it in two variables like: <code>CC_FS_BUCKET</code> and replace <code>/some/empty/folder</code> with <code>/public/bucket</code>.

You will end up with something like <code>/public/bucket:bucket-your-bucket-id-fsbucket.services.clever-cloud.com</code>.

Now type in your terminal <code>$ clever env set CC_FS_BUCKET /public/bucket:bucket-your-bucket-id-fsbucket.services.clever-cloud.com</code>.
<h3 id="deployment">Deployment</h3>
Just write in your terminal <code>$ clever deploy</code>. From that point, you will see your deployment logs in your terminal and will be able to see them in your Clever Cloud console in your browser. Visit your application with <code>$ clever open</code> once deployment phase is completed.

Of course you will see a screen like this on the first time you connect to your application. It's because there are no URLs generated in our <code>config/routes.rb</code> at this point.
<figure><img style="width: 450px; margin: 0 auto; display: block; max-width: 100%;" src="https://cdn.clever-cloud.com/uploads/2021/08/rails-no-controller.png" alt="Rails no controller error page" /></figure>
<h2 id="happy-coding">Happy coding!</h2>
You definitely can use this fresh template as a development environment. Here is a little extra if you don't know how to keep your commits clean while deploying them in pre-production.
<h3 id="my-workflow-to-use-clever-cloud-as-dev-env">My workflow to use Clever Cloud as dev env</h3>
<ul>
 	<li>I locally create a git branch with <code>git checkout -b &lt;my_branch_name&gt;</code>, the name evokes the feature I'll be working on.</li>
 	<li>I use <a href="https://en.wikipedia.org/wiki/Test-driven_development">TDD</a> as coding methodology (on rails I'd suggest you start with <a href="https://github.com/thoughtbot/factory_bot">FactoryBot</a> and <a href="http://rspec.info/">RSpec</a>) so I code all my tests for the feature, then commit them all on my branch.</li>
 	<li>I code my feature and create a new commit.</li>
 	<li>I can test on production conditions how the modifications behave by pushing my specific branch to master by doing <code>$ git push clever my_branch_name:master</code> (you need to push local commits on your branch before).</li>
 	<li>If I'm not satisfied with the changes I can make new changes, add the files to git then <code>$ git commit --amend</code> to add the modifications to the <em>last</em> commit without having to make a new one.</li>
</ul>
This way I can see the changes without having to edit directly on master.

You just need to redeploy your application with <code>$ clever restart</code> to get master back at its original state.]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="clevercloud dev env ror" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/clevercloud-dev-env-ror-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p>In this tutorial we are going to install the latest version of RubyOnRails and deploy it on Clever Cloud to use it as a development environment.

<span id="more-2820"></span>
<h2 id="prerequisites">Prerequisites</h2>
This article presumes you already are a RubyOnRails developer. If you are not and want to learn RubyOnRails, <a href="https://guides.rubyonrails.org/getting_started.html">start here</a> with the official documentation.

From the technical point of view, I presume you already have an installed ruby version &gt;= 2.5.0 and a version of rubygems &gt;= 1.8.11.

I also assume you know what Clever Cloud is. If you don't you maybe want to read <a href="https://www.clever.cloud/en/">this</a> first.
<h2 id="rails-local-installation">Rails local installation</h2>
In your favorite terminal type <code>$ gem install rails --pre</code>. Of course you can install any rails version you would like to use with <code>$ gem install rails -v X.X.X</code>.

After the installation logs, type in <code>$ rails new &lt;your_project_name&gt;</code> then <code>$ cd &lt;your_project_name&gt;</code>.

From now I will always assume your are currently located at this path in your terminal.
<h2 id="super-fast-version">Super fast version</h2>
If you prefer to read the docs, here is all you need:
<ul>
 	<li><a href="https://www.clever.cloud/developers/doc/applications/ruby/">Deploying ruby on rails application.</a></li>
 	<li><a href="https://www.clever.cloud/developers/addons/postgresql/">Docs for PostgreSQL add-on</a>.</li>
 	<li><a href="https://www.clever.cloud/developers/addons/fs_buckets/">Docs for FSBuckets filestystems</a>(optional).</li>
 	<li><a href="https://www.clever.cloud/developers/clever-tools/getting_started/">Docs for the clever-tools CLI</a>.</li>
</ul>
<h2 id="step-by-step-version">Step by step version</h2>
<h2 id="get-your-app-ready-for-production">Get your app ready for production</h2>
<h3 id="database-settings">Database settings</h3>
With your favorite text editor open <code>./config/database.yml</code>. Replace the generated content at <code>default: &amp;default</code> with
<pre><code class="language-yaml">default: &amp;default
  adapter: postgresql
  encoding: unicode
  timeout: 5000
</code></pre>
do the same with what's under <code>production:</code> with
<pre><code class="language-yaml">production:
  &lt;&lt;: *default
  database: &lt;%= ENV['POSTGRESQL_ADDON_DB'] %&gt;
  username: &lt;%= ENV['POSTGRESQL_ADDON_USER'] %&gt;
  password: &lt;%= ENV['POSTGRESQL_ADDON_PASSWORD'] %&gt;
  host: &lt;%= ENV['POSTGRESQL_ADDON_HOST'] %&gt;
  port: &lt;%= ENV['POSTGRESQL_ADDON_PORT'] %&gt;
</code></pre>
Save the file.
<h3 id="dependencies-settings">Dependencies settings</h3>
Open <code>./Gemfile</code> with your text editor and replace
<pre><code class="language-bash"># Use sqlite3 as the database for Active Record
gem 'sqlite3', '~&gt; 1.4'
</code></pre>
with
<pre><code class="language-bash"># Use postgresql as the database for Active Record
gem 'pg'
</code></pre>
and save the file. Run <code>$ bundle install</code> to have <code>Gemfile.lock</code> updated.
<h3 id="deployment-orchestration-settings">Deployment orchestration settings</h3>
In your terminal create a new folder <code>$ mkdir clevercloud</code>

create a new file <code>$ touch clevercloud/ruby.json</code>.

Open the new file <code>./clevercloud/ruby.json</code> with a text editor and add the following
<pre><code class="language-json">{
  "deploy" : {
    "rakegoals": ["db:migrate", "assets:precompile"],
    "static": "/public"
  }
}
</code></pre>
Don't forget to commit your file and push it.
<h2 id="clever-cloud-configuration">Clever Cloud configuration</h2>
<h3 id="i-dont-have-an-account">I don't have an account</h3>
Simply sign up <a href="https://api.clever-cloud.com/v2/session/signup">here</a>. You will get an email for email address validation. Just click the link, you will be redirected to the Clever Cloud console with your free credits unlocked.

Jump to <strong>Creating the application</strong> section and skip the login part.
<h3 id="i-have-an-account">I have an account</h3>
Go to the <a href="https://console.clever-cloud.com/">Clever Cloud console</a> and log in.
<h3 id="creating-the-application">Creating the application</h3>
You are now logged in the Clever Cloud console. Under your organisation select <code>+ Create</code>, on the next screen click <code>Brand new app</code>.

Select the <code>Ruby</code> language, click <code>Edit</code> and select the CPU size you need. I would suggest for a dev environment you select the smallest one and scale when you need more resources. Finish editing this part with <code>Next</code>.

Name your application in the following screen, for next references to that name, I will use <code>&lt;your_application_name&gt;</code>. Add a little description if you want to. Select your deployment zone (where the code will be physically hosted) and finish this section with next.
<h3 id="database-setup">Database setup</h3>
On the next screen, scroll until you find <code>PostgreSQL</code> and select this add-on. Select the database size you need and click <code>Next</code> in the bottom right. Name your database and select the same location as the one you picked for your ruby application.
<h3 id="setting-environment-variables">Setting environment variables</h3>
In the following screen you see an interface to add additional environment variables. Don't change or erase those already set up, unless you know what you are doing and why you need to do so.
<h4 id="secret_key_base">SECRET_KEY_BASE</h4>
In your terminal generate a secret key with <code>$ rake secret</code>. Copy the key you obtained and paste it in the Clever Cloud console as an environment variable value under those already present. As a name, use <code>SECREY_KEY_BASE</code> and click <code>ADD</code>.
<h4 id="ruby_version">RUBY_VERSION</h4>
Check if a ruby version is specified with <code>$ cat ./Gemfile</code>. If so click <code>Next</code> and go straight to the next chapter.

If not use your ruby version manager to check the current version. E.g with <a href="https://rvm.io/">rvm</a>: <code>$ rvm current</code> Output: <code>$ ruby-2.6.0</code> So in the environment variables editor add <code>RUBY_VERSION</code> as name, and in this case <code>2.6.0</code> as value. Click <code>ADD</code>, then <code>Next</code>.
<h3 id="i-need-a-filesystem">I need a filesystem</h3>
Click on the left panel on <code>+ Create</code> and this time, select <code>an add-on</code>, and scroll until you find <code>FS Bucket</code>. Just click <code>Next</code> on the following screen. A list of your applications will be displayed. Link it with <code>&lt;your_application_name&gt;</code>. Select <code>Next</code> again, and now, name your Bucket and select the same deployment zone as for your application and database. <code>Next</code>.
<h2 id="deploying-the-application">Deploying the application!</h2>
We will use the <a href="https://github.com/CleverCloud/clever-tools">Clever Cloud CLI</a> for that.
<h3 id="the-clever-cloud-cli">The Clever Cloud CLI</h3>
most common installations:

<strong>npm</strong>: <code>$ npm install -g clever-tools</code>

<strong>brew</strong>: <code>$ brew install CleverCloud/homebrew-tap/clever-tools</code>

<strong>linux</strong>:
<pre><code class="language-bash">$ curl https://clever-tools.cellar.services.clever-cloud.com/releases/latest/clever-tools-latest_linux.tar.gz
$ tar xvzf clever-tools-latest_linux.tar.gz
$ cp clever-tools-latest_linux/clever ~/.local/bin/
</code></pre>
For extended informations, check out <a href="https://www.clever.cloud/developers/clever-tools/getting_started/">this guide</a>.

Once the CLI is installed, login with <code>$ clever login</code>. A browser page will open. Enter your Clever Cloud account's credentials and go back to your terminal.

Link your application with <code>$ clever link &lt;your_application_name&gt;</code>.

If for some reason you have <code>$ [ERROR] Application not found</code> as an output, in the Clever Cloud console go in <code>&lt;your_application_name&gt;</code> and select the <code>Information</code> menu.

Copy the value of <code>Application ID</code> and in your terminal now type <code>$ clever link &lt;the value of Application ID&gt;</code>.
<h4 id="i-have-a-filesystem-only-if-you-have-followed-i-need-a-filesystem">I have a filesystem (only if you have followed #I need a filesystem)</h4>
Go in the Clever Cloud console, and find the <code>Informations</code> page of the File System Bucket you previously created.

Copy the first environment variable displayed, it should look as follows:

<code>CC_FS_BUCKET=/some/empty/folder:bucket-your-bucket-id-fsbucket.services.clever-cloud.com</code>.

Split it in two variables like: <code>CC_FS_BUCKET</code> and replace <code>/some/empty/folder</code> with <code>/public/bucket</code>.

You will end up with something like <code>/public/bucket:bucket-your-bucket-id-fsbucket.services.clever-cloud.com</code>.

Now type in your terminal <code>$ clever env set CC_FS_BUCKET /public/bucket:bucket-your-bucket-id-fsbucket.services.clever-cloud.com</code>.
<h3 id="deployment">Deployment</h3>
Just write in your terminal <code>$ clever deploy</code>. From that point, you will see your deployment logs in your terminal and will be able to see them in your Clever Cloud console in your browser. Visit your application with <code>$ clever open</code> once deployment phase is completed.

Of course you will see a screen like this on the first time you connect to your application. It's because there are no URLs generated in our <code>config/routes.rb</code> at this point.
<figure><img style="width: 450px; margin: 0 auto; display: block; max-width: 100%;" src="https://cdn.clever-cloud.com/uploads/2021/08/rails-no-controller.png" alt="Rails no controller error page" /></figure>
<h2 id="happy-coding">Happy coding!</h2>
You definitely can use this fresh template as a development environment. Here is a little extra if you don't know how to keep your commits clean while deploying them in pre-production.
<h3 id="my-workflow-to-use-clever-cloud-as-dev-env">My workflow to use Clever Cloud as dev env</h3>
<ul>
 	<li>I locally create a git branch with <code>git checkout -b &lt;my_branch_name&gt;</code>, the name evokes the feature I'll be working on.</li>
 	<li>I use <a href="https://en.wikipedia.org/wiki/Test-driven_development">TDD</a> as coding methodology (on rails I'd suggest you start with <a href="https://github.com/thoughtbot/factory_bot">FactoryBot</a> and <a href="http://rspec.info/">RSpec</a>) so I code all my tests for the feature, then commit them all on my branch.</li>
 	<li>I code my feature and create a new commit.</li>
 	<li>I can test on production conditions how the modifications behave by pushing my specific branch to master by doing <code>$ git push clever my_branch_name:master</code> (you need to push local commits on your branch before).</li>
 	<li>If I'm not satisfied with the changes I can make new changes, add the files to git then <code>$ git commit --amend</code> to add the modifications to the <em>last</em> commit without having to make a new one.</li>
</ul>
This way I can see the changes without having to edit directly on master.

You just need to redeploy your application with <code>$ clever restart</code> to get master back at its original state.]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>One Framework a Day keeps the Boredom Away: Sinatra</title>
		<link>https://www.clever.cloud/blog/features/2017/10/16/1fdba-sinatra/</link>
		
		<dc:creator><![CDATA[Marc-Antoine Perennou]]></dc:creator>
		<pubDate>Mon, 16 Oct 2017 17:15:00 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[1fdba]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[puma]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[sinatra]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2017/10/16/1fdba-sinatra/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="1fdba sinatra 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><p>Welcome to this new edition of <a href="/blog/features/2017/10/09/1fdba-step0/">One Framework a Day keeps the Boredom Away</a>. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it&#39;s about Sinatra.</p>
<span id="more-2910"></span>

<p>In each post of this series we&#39;ll see how to deploy a particular framework on Clever Cloud. Today we are taking a look at <a href="http://www.sinatrarb.com/">Sinatra</a>.</p>
<p>If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI <a href="https://github.com/CleverCloud/clever-tools">Clever-Tools</a>.</p>
<h2 id="what-is-sinatra">What is Sinatra?</h2>
<blockquote>
Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort
</blockquote>

<p>It&#39;s been around for 10 years now and has already inspired several other framework since then. Ratpack which was <a href="/blog/features/2017/10/12/ratpack/">showcased last week</a> has been heavily inspired by sinatra for instance.  Our own <a href="https://twitter.com/Keruspe/">Keruspe</a> wanted to play with a couple of Ruby technologies like Puma and Sinatra. And so he built a <a href="https://github.com/CleverCloud/demo-sinatra-puma-activerecord">sample project</a> for it. That&#39;s what we are going to deploy today.</p>
<h2 id="setup">Setup</h2>
<ul>
<li>Start by cloning the sources: <code>git clone https://github.com/CleverCloud/demo-sinatra-puma-activerecord</code></li>
<li>Create the database you want to use, in my case Postgres: <code>clever addon create postgresql-addon --plan dev --region eu sinatraPG</code></li>
<li>Create the Ruby application on Clever Cloud: <code>clever create --type ruby sinatraSample --region par</code></li>
<li>Link the Postgres add-on to the application: <code>clever service link-addon sinatraPG</code></li>
<li>Tell Clever Cloud to deploy the API using puma (the default is uwsgi as of now): <code>clever env set CC_RACKUP_SERVER puma</code></li>
<li>Tell Clever Cloud to run database migrations before launching the API:<code>clever env set CC_PRE_RUN_HOOK &#39;bundle exec rake db:migrate&#39;</code></li>
<li>Add a domain name: <code>clever domain add mySinatraSample.cleverapps.io</code></li>
</ul>
<p>Specify the maximum number of PG connections your application will use (depending on the selected plan) by adding an environment variable like <code>DB_POOL=5</code> if you want to use 5 connections. For production, you should also set:</p>
<pre><code class="language-bash">clever env set RACK_ENV production
clever env set RAILS_ENV production
</code></pre>
<h2 id="deploy">Deploy</h2>
<ul>
<li>Deploy the application with <code>clever deploy</code></li>
</ul>
<p>And you are up and running. This application provides an API to store users. They only have a name field. Users can be created with a POST request and retrieve with a GET request like so:  </p>
<ul>
<li>Create an object with <code>curl --data &quot;regis&quot;  https://mySinatraSample.cleverapps.io</code></li>
<li>Retrieve that object with <code>curl https://mySinatraSample.cleverapps.io/regis</code></li>
</ul>
<p>Everything works out of the box because this application has been written for Clever Cloud. If you take a look at the condfiguration file under <code>./config/database.yml</code> you should see some environment variables being used. They are the one provided by our Postgres add-on. You can get the full list of variables with <code>clever env</code>.</p>
<p>Let us know your thoughts on this in the comments below. We will be back tomorrow for another post :)</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="1fdba sinatra 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-sinatra-1-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><p>Welcome to this new edition of <a href="/blog/features/2017/10/09/1fdba-step0/">One Framework a Day keeps the Boredom Away</a>. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it&#39;s about Sinatra.</p>
<span id="more-2910"></span>

<p>In each post of this series we&#39;ll see how to deploy a particular framework on Clever Cloud. Today we are taking a look at <a href="http://www.sinatrarb.com/">Sinatra</a>.</p>
<p>If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI <a href="https://github.com/CleverCloud/clever-tools">Clever-Tools</a>.</p>
<h2 id="what-is-sinatra">What is Sinatra?</h2>
<blockquote>
Sinatra is a DSL for quickly creating web applications in Ruby with minimal effort
</blockquote>

<p>It&#39;s been around for 10 years now and has already inspired several other framework since then. Ratpack which was <a href="/blog/features/2017/10/12/ratpack/">showcased last week</a> has been heavily inspired by sinatra for instance.  Our own <a href="https://twitter.com/Keruspe/">Keruspe</a> wanted to play with a couple of Ruby technologies like Puma and Sinatra. And so he built a <a href="https://github.com/CleverCloud/demo-sinatra-puma-activerecord">sample project</a> for it. That&#39;s what we are going to deploy today.</p>
<h2 id="setup">Setup</h2>
<ul>
<li>Start by cloning the sources: <code>git clone https://github.com/CleverCloud/demo-sinatra-puma-activerecord</code></li>
<li>Create the database you want to use, in my case Postgres: <code>clever addon create postgresql-addon --plan dev --region eu sinatraPG</code></li>
<li>Create the Ruby application on Clever Cloud: <code>clever create --type ruby sinatraSample --region par</code></li>
<li>Link the Postgres add-on to the application: <code>clever service link-addon sinatraPG</code></li>
<li>Tell Clever Cloud to deploy the API using puma (the default is uwsgi as of now): <code>clever env set CC_RACKUP_SERVER puma</code></li>
<li>Tell Clever Cloud to run database migrations before launching the API:<code>clever env set CC_PRE_RUN_HOOK &#39;bundle exec rake db:migrate&#39;</code></li>
<li>Add a domain name: <code>clever domain add mySinatraSample.cleverapps.io</code></li>
</ul>
<p>Specify the maximum number of PG connections your application will use (depending on the selected plan) by adding an environment variable like <code>DB_POOL=5</code> if you want to use 5 connections. For production, you should also set:</p>
<pre><code class="language-bash">clever env set RACK_ENV production
clever env set RAILS_ENV production
</code></pre>
<h2 id="deploy">Deploy</h2>
<ul>
<li>Deploy the application with <code>clever deploy</code></li>
</ul>
<p>And you are up and running. This application provides an API to store users. They only have a name field. Users can be created with a POST request and retrieve with a GET request like so:  </p>
<ul>
<li>Create an object with <code>curl --data &quot;regis&quot;  https://mySinatraSample.cleverapps.io</code></li>
<li>Retrieve that object with <code>curl https://mySinatraSample.cleverapps.io/regis</code></li>
</ul>
<p>Everything works out of the box because this application has been written for Clever Cloud. If you take a look at the condfiguration file under <code>./config/database.yml</code> you should see some environment variables being used. They are the one provided by our Postgres add-on. You can get the full list of variables with <code>clever env</code>.</p>
<p>Let us know your thoughts on this in the comments below. We will be back tomorrow for another post :)</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>One Framework a Day keeps the Boredom Away: Ruby on Rails with Redmine</title>
		<link>https://www.clever.cloud/blog/features/2017/10/11/1fdba-rails-redmine/</link>
		
		<dc:creator><![CDATA[Laurent Doguin]]></dc:creator>
		<pubDate>Wed, 11 Oct 2017 19:15:00 +0000</pubDate>
				<category><![CDATA[Features]]></category>
		<category><![CDATA[1fdba]]></category>
		<category><![CDATA[fsbucket]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2017/10/11/1fdba-rails-redmine/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="1fdba ror 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p>Welcome to this new edition of <a href="/blog/features/2017/10/09/1fdba-step0/">One Framework a Day keeps the Boredom Away</a>. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it's about Ruby on Rails.

<span id="more-2907"></span>

In each post of this series we'll see how to deploy a particular framework on Clever Cloud. Today we are taking a look at <a href="https://rubyonrails.org/">Ruby on Rails</a>.

If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI <a href="https://github.com/CleverCloud/clever-tools">Clever-Tools</a>.
<h2 id="what-is-ruby-on-rails">What is Ruby on Rails?</h2>
<blockquote>Ruby on Rails, or simply Rails, is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller framework, providing default structures for a database, a web service, and web pages.</blockquote>
There are lots of applications built on top of Ruby on Rails. Today I decided to look at <a href="https://github.com/edavis10/redmine">Redmine</a>. It's a project management web application. You can read our documentation on <a href="https://www.clever.cloud/developers/doc/applications/ruby/">Rails</a> first and then folow this tutorial.
<h2 id="setup">Setup</h2>
<ul>
 	<li>Start by cloning the sources, here I am checking out the latest stable branch: <code>git clone https://github.com/edavis10/redmine/ --branch 3.4-stable</code></li>
 	<li>Create the database you want to use, in my case Postgres: <code>clever addon create postgresql-addon --plan dev --region eu redminePG</code></li>
 	<li>Create a <a href="https://www.clever.cloud/developers/addons/fs_buckets/">FS Bucket</a>: <code>clever addon create fs-bucket --plan s --region eu redmineFS</code></li>
 	<li>Create the Ruby application on Clever Cloud: <code>clever create --type ruby redmine --region par</code></li>
 	<li>Link the Postgres add-on to the application: <code>clever service link-addon redminePG</code></li>
 	<li>Link the FS Bucket add-on to the application: <code>clever service link-addon redmineFS</code></li>
</ul>
It's time to configure the application with environment variables. To get a list of the already available variables simply run <code>clever env</code>. You will notice all the variables related to PostgreSQL. To use them create a new <code>database.yml</code> file under <code>config</code>: <code>touch config/database.yml</code>
<pre><code class="language-yaml">production:
  adapter: postgresql
  database: &lt;%= ENV["POSTGRESQL_ADDON_DB"] %&gt;
  host: &lt;%= ENV["POSTGRESQL_ADDON_HOST"] %&gt;
  username: &lt;%= ENV["POSTGRESQL_ADDON_USER"] %&gt;
  port: &lt;%= ENV["POSTGRESQL_ADDON_PORT"] %&gt;
  password: &lt;%= ENV["POSTGRESQL_ADDON_PASSWORD"] %&gt;
  encoding: utf8
</code></pre>
<ul>
 	<li>Define a new global secret in <code>config/secrets.yml</code>: <code>touch config/secrets.yml</code>
<pre><code class="language-yaml">production:
  secret_key_base: &lt;%= ENV["SECRET_KEY_BASE"] %&gt;
</code></pre>
</li>
 	<li>Define all the other configuration variables under <code>config/configuration.yml</code>: <code>touch config/configuration.yml</code>
<pre><code class="language-yaml">production:
  attachments_storage_path: &lt;%= ENV["APP_HOME"] %&gt;&lt;%= ENV["ATTACHMENTS_STORAGE_PATH"] %&gt;
</code></pre>
</li>
</ul>
The following property uses two different variables. <em>APP_HOME</em> is already available and injected when the VM starts. It's the absolute path to the application repository. The second one is to tell Redmine where to write files.

Time to install the dependencies with <code>./bin/bundle install --without development test</code>. And now setup the various environment variables you will need:
<ul>
 	<li>Set the Ruby version: <code>clever env set RUBY_VERSION 2.3.1</code></li>
 	<li>Setup the Rails environment to use the production configuration: <code>clever env set RAILS_ENV production</code></li>
 	<li>Use <code>en</code> as language: <code>clever env set REDMINE_LANG en</code></li>
 	<li>Use a newly generated secret: <code>clever env set SECRET_KEY_BASE `./bin/rake secret` </code></li>
 	<li>Setup where to write files: <code>clever env set ATTACHMENTS_STORAGE_PATH /data/attachments</code></li>
 	<li>Define where to mount our FS Bucket:<code>clever env set CC_FS_BUCKET /data:`clever env | awk  -F = '/BUCKET_HOST/ { print $2}'` </code></li>
</ul>
The FS bucket is one of the add-ons we setup earlier. It's a FileSystem mounted when the VM starts. Here it's mounted under <code>/public</code>. This path being relative to the home of the application, which is what we had under <em>APP_HOME</em> earlier. The second part of the <em>CC_FS_BUCKET</em> variable separated by a semi-colon is the host for your FS Bucket. It's already available under the <em>BUCKET_HOST</em> variable.

Now Redmine requires to write in some folder, and those folder to be pre-created. To make sure this executed each time the app is ran, we can use a pre-run hook. It will run something each time prior to starting the app. Let's start with the script:

<code>mkdir clevercloud; touch clevercloud/initDirectories.sh &amp;&amp; chmod +x clevercloud/initDirectories.sh</code>
<pre><code class="language-bash">[ -d tmp ] || mkdir tmp
[ -d tmp/pdf ] || mkdir tmp/pdf
[ -d data/plugin_assets ] || mkdir data/plugin_assets
[ -d tmp/pdf ] || mkdir tmp/pdf
[ -d data/attachments ] || mkdir data/attachments
</code></pre>
It first tests the existence of the folder and if it does not exist, creates it. To make sure it's run add the hook like this: <code>clever env set CC_PRE_RUN_HOOK ./clevercloud/initDirectories.sh</code>

The minimum configuration is ready, we can move on to the deployment phase.
<h2 id="deploy">Deploy</h2>
As usual with Clever Cloud the deployment phase is tied to the runtime and build tool used by the application. Here it's a Ruby app so we are going to create a ruby.json file: <code>touch clevercloud/ruby.json</code>
<pre><code class="language-json">{
  "deploy" : {
    "rakegoals": ["db:migrate"],
    "sidekiq": true
  }
}
</code></pre>
Now we need to commit our changes. Create a new deployment branch, commit your stuff and deploy!
<pre><code class="language-bash">git checkout -b clever/deploy
git add Gemfile.lock clevercloud/initDirectories.sh clevercloud/ruby.json config/configuration.yml config/database.yml config/secrets.yml
git commit -m"add clever specifics"
clever deploy
</code></pre>
Last command is the equivalent of <code>git push clever yourBranch</code> where clever is a remote branch that was added when you created the application with the CLI at the very begining.

There is one last thing we can do. In Redmine's documentation they mention some default data you can import by running a rake task. Since we don't want to run these tasks each time we restart the application, we can SSH on the VM and execute them here. Run <code>clever ssh</code>. This will open a connection to the VM. From here you can execute that task:
<pre><code class="language-bash">[ldoguin@caolila redmine]$ clever ssh
Opening an ssh shell.
Warning: Permanently added '[195.154.154.198]:40707' (ED25519) to the list of known hosts.
bas@76afae97-762c-43ee-b861-d5db873b553d ~ $ cd app_58f97386-2ec5-48b6-a774-31d64241f692/
bas@76afae97-762c-43ee-b861-d5db873b553d ~/app_58f97386-2ec5-48b6-a774-31d64241f692 $ RAILS_ENV=production bundle exec rake redmine:load_default_data
Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, es-PA, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] 
====================================
Default configuration data loaded.
bas@76afae97-762c-43ee-b861-d5db873b553d ~/app_58f97386-2ec5-48b6-a774-31d64241f692 $ 
</code></pre>
If you have tasks to run regularly you can also configure a cron by adding a json fle as explained in <a href="https://www.clever.cloud/developers/doc/administrate/cron/">our documentation</a>.

To test this, I invite you to run <code>clever open</code>. This should open the running application in your default browser. By default you can login with admin/admin. I invite you to create a project, an issue and add an attachment to that issue. If everything works correctly you can go in our web console, click on redmineFS and then on File Explorer. You should be able to explore your FS bucket and see the file you attached to the issue :)

<img src="https://www2.cleverapps.io/app/uploads/2021/08/redmineFsBucket.png" alt="Application environment variables" />

What's also interesting here is that everything is configured with env variable so you can use the same code for prod and preprod or staging if you want to.
<h2 id="setup-and-deploy-a-preproduction-redmine">Setup and Deploy a Preproduction Redmine</h2>
You did most of the work already :) Just don't forget to use the <code>--alias</code> option to specify which application you are working with.
<pre><code class="language-bash">clever addon create postgresql-addon --plan s --region eu redminePG
clever addon create fs-bucket --plan s --region eu staging-redmineFS
clever create --type ruby staging-redmine --region par
clever service --alias staging-redmine link-addon staging-redminePG
clever service --alias staging-redmine link-addon staging-redmineFS
clever env --alias staging-redmine set RUBY_VERSION 2.3.1
clever env --alias staging-redmine set RAILS_ENV production
clever env --alias staging-redmine set REDMINE_LANG en
clever env --alias staging-redmine set SECRET_KEY_BASE `./bin/rake secret`
clever env --alias staging-redmine set ATTACHMENTS_STORAGE_PATH /data/attachments
clever env --alias staging-redmine set CC_FS_BUCKET /data:`clever env --alias staging-redmine  | awk  -F = '/BUCKET_HOST/ { print $2}'`
clever env --alias staging-redmine set CC_PRE_RUN_HOOK ./clevercloud/initDirectories.sh
clever deploy --alias staging-redmine
</code></pre>
Then you can inject the default data just like before. As you can see most of the work here was to make sure Redmine could be configured with environment variables. Some Rails projects, or other projects in general, are more or less compliant with <a href="https://12factor.net/">12 factors</a> and as such require some work.

Hopefuly you liked what you read. This is a very minimal setup to enjoy Redmine, there are other things to configure like the SMTP server or some plugins to be added. That's up to you :)]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1.png" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="1fdba ror 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1.png 1400w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-300x116.png 300w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-1024x395.png 1024w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-768x296.png 768w, https://cdn.clever-cloud.com/uploads/2021/08/1fdba-ror-1-1368x528.png 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p>Welcome to this new edition of <a href="/blog/features/2017/10/09/1fdba-step0/">One Framework a Day keeps the Boredom Away</a>. In this series I will show you how to deploy a particular framework on Clever Cloud every day until I want to go back to boredom. Today it's about Ruby on Rails.

<span id="more-2907"></span>

In each post of this series we'll see how to deploy a particular framework on Clever Cloud. Today we are taking a look at <a href="https://rubyonrails.org/">Ruby on Rails</a>.

If you want to tag along, make sure you have git, a Clever Cloud account and that you have installed our CLI <a href="https://github.com/CleverCloud/clever-tools">Clever-Tools</a>.
<h2 id="what-is-ruby-on-rails">What is Ruby on Rails?</h2>
<blockquote>Ruby on Rails, or simply Rails, is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller framework, providing default structures for a database, a web service, and web pages.</blockquote>
There are lots of applications built on top of Ruby on Rails. Today I decided to look at <a href="https://github.com/edavis10/redmine">Redmine</a>. It's a project management web application. You can read our documentation on <a href="https://www.clever.cloud/developers/doc/applications/ruby/">Rails</a> first and then folow this tutorial.
<h2 id="setup">Setup</h2>
<ul>
 	<li>Start by cloning the sources, here I am checking out the latest stable branch: <code>git clone https://github.com/edavis10/redmine/ --branch 3.4-stable</code></li>
 	<li>Create the database you want to use, in my case Postgres: <code>clever addon create postgresql-addon --plan dev --region eu redminePG</code></li>
 	<li>Create a <a href="https://www.clever.cloud/developers/addons/fs_buckets/">FS Bucket</a>: <code>clever addon create fs-bucket --plan s --region eu redmineFS</code></li>
 	<li>Create the Ruby application on Clever Cloud: <code>clever create --type ruby redmine --region par</code></li>
 	<li>Link the Postgres add-on to the application: <code>clever service link-addon redminePG</code></li>
 	<li>Link the FS Bucket add-on to the application: <code>clever service link-addon redmineFS</code></li>
</ul>
It's time to configure the application with environment variables. To get a list of the already available variables simply run <code>clever env</code>. You will notice all the variables related to PostgreSQL. To use them create a new <code>database.yml</code> file under <code>config</code>: <code>touch config/database.yml</code>
<pre><code class="language-yaml">production:
  adapter: postgresql
  database: &lt;%= ENV["POSTGRESQL_ADDON_DB"] %&gt;
  host: &lt;%= ENV["POSTGRESQL_ADDON_HOST"] %&gt;
  username: &lt;%= ENV["POSTGRESQL_ADDON_USER"] %&gt;
  port: &lt;%= ENV["POSTGRESQL_ADDON_PORT"] %&gt;
  password: &lt;%= ENV["POSTGRESQL_ADDON_PASSWORD"] %&gt;
  encoding: utf8
</code></pre>
<ul>
 	<li>Define a new global secret in <code>config/secrets.yml</code>: <code>touch config/secrets.yml</code>
<pre><code class="language-yaml">production:
  secret_key_base: &lt;%= ENV["SECRET_KEY_BASE"] %&gt;
</code></pre>
</li>
 	<li>Define all the other configuration variables under <code>config/configuration.yml</code>: <code>touch config/configuration.yml</code>
<pre><code class="language-yaml">production:
  attachments_storage_path: &lt;%= ENV["APP_HOME"] %&gt;&lt;%= ENV["ATTACHMENTS_STORAGE_PATH"] %&gt;
</code></pre>
</li>
</ul>
The following property uses two different variables. <em>APP_HOME</em> is already available and injected when the VM starts. It's the absolute path to the application repository. The second one is to tell Redmine where to write files.

Time to install the dependencies with <code>./bin/bundle install --without development test</code>. And now setup the various environment variables you will need:
<ul>
 	<li>Set the Ruby version: <code>clever env set RUBY_VERSION 2.3.1</code></li>
 	<li>Setup the Rails environment to use the production configuration: <code>clever env set RAILS_ENV production</code></li>
 	<li>Use <code>en</code> as language: <code>clever env set REDMINE_LANG en</code></li>
 	<li>Use a newly generated secret: <code>clever env set SECRET_KEY_BASE `./bin/rake secret` </code></li>
 	<li>Setup where to write files: <code>clever env set ATTACHMENTS_STORAGE_PATH /data/attachments</code></li>
 	<li>Define where to mount our FS Bucket:<code>clever env set CC_FS_BUCKET /data:`clever env | awk  -F = '/BUCKET_HOST/ { print $2}'` </code></li>
</ul>
The FS bucket is one of the add-ons we setup earlier. It's a FileSystem mounted when the VM starts. Here it's mounted under <code>/public</code>. This path being relative to the home of the application, which is what we had under <em>APP_HOME</em> earlier. The second part of the <em>CC_FS_BUCKET</em> variable separated by a semi-colon is the host for your FS Bucket. It's already available under the <em>BUCKET_HOST</em> variable.

Now Redmine requires to write in some folder, and those folder to be pre-created. To make sure this executed each time the app is ran, we can use a pre-run hook. It will run something each time prior to starting the app. Let's start with the script:

<code>mkdir clevercloud; touch clevercloud/initDirectories.sh &amp;&amp; chmod +x clevercloud/initDirectories.sh</code>
<pre><code class="language-bash">[ -d tmp ] || mkdir tmp
[ -d tmp/pdf ] || mkdir tmp/pdf
[ -d data/plugin_assets ] || mkdir data/plugin_assets
[ -d tmp/pdf ] || mkdir tmp/pdf
[ -d data/attachments ] || mkdir data/attachments
</code></pre>
It first tests the existence of the folder and if it does not exist, creates it. To make sure it's run add the hook like this: <code>clever env set CC_PRE_RUN_HOOK ./clevercloud/initDirectories.sh</code>

The minimum configuration is ready, we can move on to the deployment phase.
<h2 id="deploy">Deploy</h2>
As usual with Clever Cloud the deployment phase is tied to the runtime and build tool used by the application. Here it's a Ruby app so we are going to create a ruby.json file: <code>touch clevercloud/ruby.json</code>
<pre><code class="language-json">{
  "deploy" : {
    "rakegoals": ["db:migrate"],
    "sidekiq": true
  }
}
</code></pre>
Now we need to commit our changes. Create a new deployment branch, commit your stuff and deploy!
<pre><code class="language-bash">git checkout -b clever/deploy
git add Gemfile.lock clevercloud/initDirectories.sh clevercloud/ruby.json config/configuration.yml config/database.yml config/secrets.yml
git commit -m"add clever specifics"
clever deploy
</code></pre>
Last command is the equivalent of <code>git push clever yourBranch</code> where clever is a remote branch that was added when you created the application with the CLI at the very begining.

There is one last thing we can do. In Redmine's documentation they mention some default data you can import by running a rake task. Since we don't want to run these tasks each time we restart the application, we can SSH on the VM and execute them here. Run <code>clever ssh</code>. This will open a connection to the VM. From here you can execute that task:
<pre><code class="language-bash">[ldoguin@caolila redmine]$ clever ssh
Opening an ssh shell.
Warning: Permanently added '[195.154.154.198]:40707' (ED25519) to the list of known hosts.
bas@76afae97-762c-43ee-b861-d5db873b553d ~ $ cd app_58f97386-2ec5-48b6-a774-31d64241f692/
bas@76afae97-762c-43ee-b861-d5db873b553d ~/app_58f97386-2ec5-48b6-a774-31d64241f692 $ RAILS_ENV=production bundle exec rake redmine:load_default_data
Select language: ar, az, bg, bs, ca, cs, da, de, el, en, en-GB, es, es-PA, et, eu, fa, fi, fr, gl, he, hr, hu, id, it, ja, ko, lt, lv, mk, mn, nl, no, pl, pt, pt-BR, ro, ru, sk, sl, sq, sr, sr-YU, sv, th, tr, uk, vi, zh, zh-TW [en] 
====================================
Default configuration data loaded.
bas@76afae97-762c-43ee-b861-d5db873b553d ~/app_58f97386-2ec5-48b6-a774-31d64241f692 $ 
</code></pre>
If you have tasks to run regularly you can also configure a cron by adding a json fle as explained in <a href="https://www.clever.cloud/developers/doc/administrate/cron/">our documentation</a>.

To test this, I invite you to run <code>clever open</code>. This should open the running application in your default browser. By default you can login with admin/admin. I invite you to create a project, an issue and add an attachment to that issue. If everything works correctly you can go in our web console, click on redmineFS and then on File Explorer. You should be able to explore your FS bucket and see the file you attached to the issue :)

<img src="https://www2.cleverapps.io/app/uploads/2021/08/redmineFsBucket.png" alt="Application environment variables" />

What's also interesting here is that everything is configured with env variable so you can use the same code for prod and preprod or staging if you want to.
<h2 id="setup-and-deploy-a-preproduction-redmine">Setup and Deploy a Preproduction Redmine</h2>
You did most of the work already :) Just don't forget to use the <code>--alias</code> option to specify which application you are working with.
<pre><code class="language-bash">clever addon create postgresql-addon --plan s --region eu redminePG
clever addon create fs-bucket --plan s --region eu staging-redmineFS
clever create --type ruby staging-redmine --region par
clever service --alias staging-redmine link-addon staging-redminePG
clever service --alias staging-redmine link-addon staging-redmineFS
clever env --alias staging-redmine set RUBY_VERSION 2.3.1
clever env --alias staging-redmine set RAILS_ENV production
clever env --alias staging-redmine set REDMINE_LANG en
clever env --alias staging-redmine set SECRET_KEY_BASE `./bin/rake secret`
clever env --alias staging-redmine set ATTACHMENTS_STORAGE_PATH /data/attachments
clever env --alias staging-redmine set CC_FS_BUCKET /data:`clever env --alias staging-redmine  | awk  -F = '/BUCKET_HOST/ { print $2}'`
clever env --alias staging-redmine set CC_PRE_RUN_HOOK ./clevercloud/initDirectories.sh
clever deploy --alias staging-redmine
</code></pre>
Then you can inject the default data just like before. As you can see most of the work here was to make sure Redmine could be configured with environment variables. Some Rails projects, or other projects in general, are more or less compliant with <a href="https://12factor.net/">12 factors</a> and as such require some work.

Hopefuly you liked what you read. This is a very minimal setup to enjoy Redmine, there are other things to configure like the SMTP server or some plugins to be added. That's up to you :)]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Rails 4 apps backed by Sidekiq + Clever Cloud.</title>
		<link>https://www.clever.cloud/blog/engineering/2015/05/05/deploy-a-rails-app-using-sidekiq-on-clever-cloud/</link>
		
		<dc:creator><![CDATA[Julien Durillon]]></dc:creator>
		<pubDate>Tue, 05 May 2015 15:32:00 +0000</pubDate>
				<category><![CDATA[Engineering]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tutorial]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2015/05/05/deploy-a-rails-app-using-sidekiq-on-clever-cloud/</guid>

					<description><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="rails4 sidekiq 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><p>At Clever Cloud, we want developers to be happy. To achieve that we try to adapt as quickly as we can to users needs. The other day, someone asked for <a href="http://sidekiq.org/">Sidekiq</a> support for their Rails applications.</p>
<span id="more-2798"></span>

<h2 id="whats-sidekiq">What&#39;s Sidekiq</h2>
<p>Sidekiq is a solution to run long background tasks in ruby. It works by running a background server and treating jobs stored in a Redis. It&#39;s helpful to delay tasks, take a long API call to the background while still be able to answer to a request in a timely manner.</p>
<h2 id="how-do-i-use-sidekiq-on-clever-cloud">How do I use Sidekiq on Clever Cloud?</h2>
<p>First, you need a Redis instance. Start by provisioning a redis addon on Clever Cloud. Remember to link the redis add-on to your application in the Console.</p>
<p>The redis addon provides a <code>REDIS_URL</code> environment variable which will be used by sidekiq to connect to the redis addon.</p>
<ul>
<li>The next and only step is to add/modify the <code>clevercloud/ruby.json</code> file to add the
&quot;sidekiq&quot; flag:</li>
</ul>
<pre><code class="language-json">{
   &quot;deploy&quot;: {
      &quot;sidekiq&quot;: true
   }
}
</code></pre>
<p>Then commit and push your application, and you should be all set!</p>
]]></description>
										<content:encoded><![CDATA[<p><img width="1400" height="540" src="https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="rails4 sidekiq 1" decoding="async" loading="lazy" srcset="https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1.jpg 1400w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-300x116.jpg 300w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-1024x395.jpg 1024w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-768x296.jpg 768w, https://cdn.clever-cloud.com/uploads/2021/08/rails4-sidekiq-1-1368x528.jpg 1368w" sizes="auto, (max-width: 1400px) 100vw, 1400px" /></p><p>At Clever Cloud, we want developers to be happy. To achieve that we try to adapt as quickly as we can to users needs. The other day, someone asked for <a href="http://sidekiq.org/">Sidekiq</a> support for their Rails applications.</p>
<span id="more-2798"></span>

<h2 id="whats-sidekiq">What&#39;s Sidekiq</h2>
<p>Sidekiq is a solution to run long background tasks in ruby. It works by running a background server and treating jobs stored in a Redis. It&#39;s helpful to delay tasks, take a long API call to the background while still be able to answer to a request in a timely manner.</p>
<h2 id="how-do-i-use-sidekiq-on-clever-cloud">How do I use Sidekiq on Clever Cloud?</h2>
<p>First, you need a Redis instance. Start by provisioning a redis addon on Clever Cloud. Remember to link the redis add-on to your application in the Console.</p>
<p>The redis addon provides a <code>REDIS_URL</code> environment variable which will be used by sidekiq to connect to the redis addon.</p>
<ul>
<li>The next and only step is to add/modify the <code>clevercloud/ruby.json</code> file to add the
&quot;sidekiq&quot; flag:</li>
</ul>
<pre><code class="language-json">{
   &quot;deploy&quot;: {
      &quot;sidekiq&quot;: true
   }
}
</code></pre>
<p>Then commit and push your application, and you should be all set!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Ruby free beta on Clever Cloud</title>
		<link>https://www.clever.cloud/blog/company/2013/09/16/ruby-beta/</link>
		
		<dc:creator><![CDATA[Regis Foucault]]></dc:creator>
		<pubDate>Mon, 16 Sep 2013 00:00:00 +0000</pubDate>
				<category><![CDATA[Company]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[rack]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<guid isPermaLink="false">https://www2.cleverapps.io/wp/blog/technology/2013/09/16/ruby-beta/</guid>

					<description><![CDATA[Version française en-dessous After three months of development and testing we are pleased to announce that Ruby is open for beta access on our platform. This famous robust natural language syntax created by Yukihiro Matsumoto is very popular among web developers. It is therefore logical that it is available today on Clever Cloud. We support [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><em><a href="#fr">Version française en-dessous</a></em></p>
<div class="pull-right" style="margin-left: 40px; margin-bottom: 40px; width: 125px;"><img decoding="async" src="https://www2.cleverapps.io/app/uploads/2021/08/ruby.png" alt="npm logo" /></div>
<p>After three months of development and testing we are pleased to announce that <a href="http://ruby-lang.org">Ruby</a> is open for beta access on our platform. This famous robust natural language syntax created by Yukihiro Matsumoto is very popular among web developers. It is therefore logical that it is available today on Clever Cloud.</p>
<p><span id="more-2732"></span></p>
<p>We support <a href="http://rack.github.io/">Rack</a>-based applications, including applications based on <a href="http://rubyonrails.org/">Rails</a> and <a href="http://www.sinatrarb.com/">Sinatra</a>.</p>
<p>You can find more information on Ruby on Rails deployments in our <a href="https://www.clever.cloud/developers/deploy/application/ruby/by-framework/ruby-on-rails/">documentation</a>. Do not hesitate to give us your <a href="mailto:support@clever-cloud.com">impressions</a>.</p>
<p>We believe that a product is never complete without the feedback of its users, so Ruby is currently in <a href="https://api.clever-cloud.com/v2/sessions/login/">free beta</a> until the final version.</p>
<p>You can keep in touch to get the pricing plans when ready on our <a href="http://clever-cloud.us1.list-manage.com/subscribe?u=0928a3dc4855008ad5808ca4e&amp;id=acad5cf9a1">mailinglist</a>.</p>
<p><em>The Clever Cloud team</em></p>
<p><a class="signup-btn" href="https://api.clever-cloud.com/v2/sessions/login/">Deploy your application for free!</a></p>
<hr id="fr" />
<p><em>Version française</em></p>
<p>Après quatre mois de développement et de tests intensifs, nous sommes heureux de vous annoncer que <a href="http://ruby-lang.org">Ruby</a> est en beta gratuite sur Clever Cloud. Ce célèbre langage robuste à la syntaxe naturelle, créé par Yukihiro Matsumoto est très prisé par les développeurs web depuis quelques années. Il est donc tout à fait logique qu’il soit disponible aujourd’hui sur Clever Cloud.</p>
<p>Nous supportons actuellement les applications basées sur <a href="http://rack.github.io/">Rack</a>, ce qui inclut les applications basées sur <a href="http://rubyonrails.org/">Rails</a> et <a href="http://www.sinatrarb.com/">Sinatra</a>.</p>
<p>Vous trouverez plus d’informations sur les déploiements Ruby on Rails dans notre <a href="https://www.clever.cloud/developers/deploy/application/ruby/by-framework/ruby-on-rails/">documentation</a>. N’hésitez pas à nous faire part de vos <a href="mailto:support@clever-cloud.com">impressions</a>.</p>
<p>Nous considérons qu’un produit n’est jamais parfait sans les retours de ses utilisateurs. Ruby est donc actuellement en <a href="https://api.clever-cloud.com/v2/sessions/login/">beta gratuite</a> jusqu’à sa version finale.</p>
<p>Vous pouvez vous tenir informé de nos offres quand elles seront prêtes via notre <a href="http://clever-cloud.us1.list-manage.com/subscribe?u=0928a3dc4855008ad5808ca4e&amp;id=acad5cf9a1">newsletter</a>.</p>
<p><em>L&#8217;équipe Clever Cloud</em></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
