<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[michelada.io - Medium]]></title>
        <description><![CDATA[We plan, code and launch awesome web and mobile products. - Medium]]></description>
        <link>https://medium.com/michelada-io?source=rss----6aae07d6a13a---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>michelada.io - Medium</title>
            <link>https://medium.com/michelada-io?source=rss----6aae07d6a13a---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 00:55:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/michelada-io" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Keep your API in shape with API Blueprint]]></title>
            <link>https://medium.com/michelada-io/keep-your-api-in-shape-with-api-blueprint-dec2f4be6dfb?source=rss----6aae07d6a13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/dec2f4be6dfb</guid>
            <category><![CDATA[blueprint]]></category>
            <category><![CDATA[api-development]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Mario Alberto Chávez]]></dc:creator>
            <pubDate>Fri, 03 Aug 2018 00:26:15 GMT</pubDate>
            <atom:updated>2018-08-03T00:26:14.574Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*WPQ3iffWUAMKACMtE_6EWA.jpeg" /></figure><p>When you are starting a new API project with Rails your first question might be: should you do it using GraphQL or just go with a good old REST API.</p><p>After much consideration, you decide to go with a REST API? Good! Continue reading this post.</p><p>Now, before you begin to consider how to implement your API, your main concern should be how to keep your API documentation up to date. This is something that always creates a sort of tension in projects where the team have to go through many hoops to keep code and docs in sync.</p><p>In a recent project, I was looking for a solution that could be easily integrated into our Rails application and at the same time allow the team to write the API definition without caring about the implementation details.</p><p>The first tool that I found was the <a href="https://github.com/zipmark/rspec_api_documentation">rspec_api_documentation</a> gem but it was incompatible with our project for two reasons: We use Minitest and it requires you to write Specs with Ruby code to describe the API.</p><p>Then I remember that in a project for one of our clients at <a href="http://michelada.io/">michelada</a> we did use Apiary as a communication tool to describe the API implemented there.</p><h3>API Blueprint</h3><p>Apiary has an Open Source format called <a href="https://apiblueprint.org/">API Blueprint</a>. It is a specification on top of Markdown that helps describe a web API. This format is oriented to creating documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S7icERm1a3_lAixs.png" /></figure><p>With this <a href="https://github.com/apiaryio/api-blueprint/blob/master/API%20Blueprint%20Specification.md">specification</a>, you can define how a request should be made and what to expect as a response from an API. Here is a sample fragment of API Blueprint that shows how to document the /questions endpoint, no code just Markdown and a special syntax <a href="https://github.com/apiaryio/mson">MSON</a> to document the response.</p><pre>FORMAT: 1A<br>HOST: http://polls.apiblueprint.org/</pre><pre># Sample API</pre><pre>Polls is a simple API allowing consumers to view polls and vote in them.</pre><pre>## Questions Collection [/questions]</pre><pre>### List All Questions [GET]</pre><pre>+ Response 200 (application/json)</pre><pre>        [<br>            {<br>                &quot;question&quot;: &quot;Favourite programming language?&quot;,<br>                &quot;published_at&quot;: &quot;2015-08-05T08:40:51.620Z&quot;,<br>                &quot;choices&quot;: [<br>                    {<br>                        &quot;choice&quot;: &quot;Swift&quot;,<br>                        &quot;votes&quot;: 2048<br>                    }, {<br>                        &quot;choice&quot;: &quot;Python&quot;,<br>                        &quot;votes&quot;: 1024<br>                    }, {<br>                        &quot;choice&quot;: &quot;Objective-C&quot;,<br>                        &quot;votes&quot;: 512<br>                    }, {<br>                        &quot;choice&quot;: &quot;Ruby&quot;,<br>                        &quot;votes&quot;: 256<br>                    }<br>                ]<br>            }<br>        ]</pre><p>MSON syntax allow us to describe JSON objects in a very simple way no matter how complicated you JSON object is. An object structure with MSON like the following:</p><pre>- address<br>    - street<br>    - city<br>    - state</pre><p>Produces a JSON object like:</p><pre>{<br>    &quot;address&quot; : {<br>        &quot;street&quot;: &quot;&quot;,<br>        &quot;city&quot;: &quot;&quot;,<br>        &quot;state&quot;: &quot;&quot;<br>    }<br>}</pre><p>The format is fairly simple to get up to speed quickly and write a complete set of API documentation. From the format is also possible to generate JSON Schema draft 4 for us, we can use these schemas to validate our API with Minitest.</p><h3>Generating good-looking documentation.</h3><p>Let’s start with the low hang fruit of using API Blueprint to document our API. Here is the documentation for two API endpoints that we are going to use in this post as an example.</p><p>The API is simple but it shows nice things about the MSON syntax like data structures reuse. It also shows how to document a response that can have many different statuses.</p><pre>FORMAT: 1A<br>HOST: https://api-test.com</pre><pre># Sample API documentation<br>We just use Markdown with special syntax to document our API.</pre><pre># Group Users<br>A User is a representation of a User on the system.</pre><pre>## Users [/users{?cursor}]<br>Endpoint for users.</pre><pre>### List Users [GET]<br>Returns a list of users paginated by the cursor.</pre><pre>+ Parameters<br>    + cursor: `10` (number, optional) - Cursor value to paginate response.</pre><pre>+ Request (application/json)<br>    + Headers</pre><pre>            Accept: application/vnd.api-test.v1+json</pre><pre>+ Response 200 (application/json)</pre><pre>    + Attributes<br>        + data (array[User], fixed-type) - Users data.<br>        + pagination (object, required) - Pagination information.<br>            + cursors (object, required) - Cursors.<br>                + after: `10` (number, required) - Cursor for next record to fetch.<br>                + next_uri: `/users?cursor=5` (string, required) - URI for next page.<br>        + links (array, fixed-type, required) - Links references.<br>            + (object)<br>                + rel: `self` (string, required)<br>                + uri: `/users` (string, required)</pre><pre>### Create User [POST]<br>Creates a new User.</pre><pre>+ Request (application/json)<br>    + Headers</pre><pre>            Accept: application/vnd.api-test.v1+json</pre><pre>    + Attributes (User Base)</pre><pre>+ Response 201 (application/json)</pre><pre>    + Attributes<br>        + data (array[User], fixed-type) - Users data.<br>        + links (array, fixed-type, required) - Links references.<br>            + (object)<br>                + rel: `self` (string, required)<br>                + uri: `/users/1` (string, required)</pre><pre>+ Response 422 (application/json)</pre><pre>    + Attributes<br>        + data (array[User Base], fixed-type) - Users data.<br>        + errors (array, fixed-type, required) - Action error.<br>            + (object)<br>                + type: `blank` (string, required) - Type of validation error.<br>                + code: `ERR-100` (string, required) - Error unique code.<br>                + message: `email can&#39;t be blank.` (string, required) - Error descriptive message.<br>                + href: `http://api-test.io/api/documentation` (string, required)<br>                  Link to learn more about the error.</pre><pre># Data Structures</pre><pre># User Base (object)<br>+ email: `user@mail.com` (string) - User&#39;s email.<br>+ first_name: `Jane` (string, required) - User&#39;s first name.<br>+ last_name: `Doe` (string, required) - User&#39;s last name.</pre><pre># User (User Base)<br>+ id (number) - User&#39;s ID.</pre><p>To render an HTML document of our documentation we can use a tool called <a href="https://github.com/danielgtaylor/aglio">aglio</a>. It parses the file and generates a nice looking document. You can choose any of the available themes or you can write your own.</p><p>In a Rails application, we install aglio with Yarn as follows</p><pre>$ bin/yarn add aglio</pre><p>The basic command, given you saved the documentation file in the docs/api folder and want to output the HTML to the /public folder, would be:</p><pre>$ bin/yarn run aglio -i docs/api/documentation.md  -o public/documentation.html</pre><p>This will produce an HTML with aglio’s default theme. You can pass additional options to choose a theme or color scheme, for more details check aglio’s documentation.</p><p>If you start the Rails server and point your browser to http://localhost:3000/documentation.html you will see your API nicely documented.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LSmjtxuzTsFqLV8W.png" /></figure><p>Let’s add a rake task to our application to generate this file by running bin/rails api:documentation. Create a file lib/tasks/api.rake and add the following lines:</p><pre>namespace :api do<br>  desc &#39;Build API documentation&#39;<br>  task :documentation do<br>    input_file = &#39;docs/api/documentation.md&#39;<br>    output_file = &#39;public/documentation.html&#39;</pre><pre>    system(&quot; bin/yarn run aglio -i #{input_file}  -o #{output_file}&quot;)<br>  end<br>end</pre><h3>Generating JSON Schemas</h3><p>Now that we have nice looking documentation its time to generate <a href="https://spacetelescope.github.io/understanding-json-schema/">JSON Schemas</a> from the documentation, with these schema files we can use Minitest to automate the verification that our API is responding in the format we expect.</p><p>There is a tool called <a href="https://github.com/o5/apib2json">api2bjon</a> that does the extraction of JSON Schemas from API Blueprint documentation. It generates a single JSON file for all schemas present in the documentation.</p><p>To generate the file with all schemas first, install apib2json and then execute it.</p><pre>$ bin/yarn apib2json<br>$ bin/yarn run apib2json --pretty -i docs/api/documentation.md  -o test/support/schemas/schemas.json</pre><p>The following is a fragment of the generated file:</p><pre>{<br>  &quot;[GET]/users{?cursor}&quot;: [<br>    {<br>      &quot;meta&quot;: {<br>        &quot;type&quot;: &quot;response&quot;,<br>        &quot;title&quot;: &quot;&quot;<br>      },<br>      &quot;schema&quot;: {<br>        &quot;$schema&quot;: &quot;http://json-schema.org/draft-04/schema#&quot;,<br>        &quot;type&quot;: &quot;object&quot;,<br>        &quot;properties&quot;: {<br>          &quot;data&quot;: {<br>            &quot;type&quot;: &quot;array&quot;,<br>            &quot;items&quot;: {<br>              &quot;type&quot;: &quot;object&quot;,<br>              &quot;properties&quot;: {<br>                &quot;email&quot;: {<br>                  &quot;type&quot;: &quot;string&quot;,<br>                  &quot;description&quot;: &quot;User&#39;s email.&quot;</pre><p>There is a problem with this file since all possible schemas are writing into this file we will need to parse the file and put each schema into its own file so we can use them with Minitest.</p><p>Unfortunately, the metadata provided by apib2json as it is, is not enough to separate schemas into independent files with unique naming. An improved version is available at <a href="https://github.com/mariochavez/apib2json/tree/additional-metadata">https://github.com/mariochavez/apib2json/tree/additional-metadata</a>.</p><p>To install apib2json from this repository execute the following command.</p><pre>$ bin/yarn add &quot;https://github.com/mariochavez/apib2json.git#additional-metadata&quot;</pre><p>Now if you regenerate the schemas file its metadata will contain additional information.</p><pre>{<br>  &quot;[GET]/users{?cursor}&quot;: [<br>    {<br>      &quot;meta&quot;: {<br>        &quot;type&quot;: &quot;response&quot;,<br>        &quot;title&quot;: null,<br>        &quot;group&quot;: &quot;Users&quot;,<br>        &quot;statusCode&quot;: &quot;200&quot;<br>      },<br>      &quot;schema&quot;: {<br>        &quot;$schema&quot;: &quot;http://json-schema.org/draft-04/schema#&quot;,<br>        &quot;type&quot;: &quot;object&quot;,<br>        &quot;properties&quot;: {<br>          &quot;data&quot;: {<br>            &quot;type&quot;: &quot;array&quot;,<br>            &quot;items&quot;: {<br>              &quot;type&quot;: &quot;object&quot;,<br>              &quot;properties&quot;: {<br>                &quot;email&quot;: {<br>                  &quot;type&quot;: &quot;string&quot;,<br>                  &quot;description&quot;: &quot;User&#39;s email.&quot;</pre><p>But as I said before, for this file be useful we need to split it to have each schema in their own file. To accomplish this let’s create a rake task. Open the file lib/tasks/api.rake and add the following code:</p><pre>desc &quot;Generate JSON schemas&quot;<br>  task :schemas do<br>    schemas_path = &quot;test/support/schemas&quot;<br>    input_file = &quot;docs/api/documentation.md&quot;<br>    output_file = &quot;test/support/schemas/schemas.json&quot;</pre><pre>    puts &quot;Generating api schemas from #{input_file}&quot;<br>    system(&quot;bin/yarn run apib2json --pretty -i #{input_file} -o #{output_file}&quot;)</pre><pre>    if File.exist?(output_file)<br>      file_path = Pathname.new(output_file)<br>      JSON.parse(file_path.read).each_pair do |group, actions|<br>        actions.each do |action|<br>          next if action.dig(&quot;meta&quot;, &quot;type&quot;) != &quot;response&quot;</pre><pre>          verb = group.scan(/\[(.*)\]/).flatten.first<br>          name = &quot;#{verb}-#{I18n.transliterate(action.dig(&#39;meta&#39;, &#39;group&#39;))}(#{action.dig(&#39;meta&#39;, &#39;statusCode&#39;)})#{action.dig(&#39;meta&#39;, &#39;title&#39;)&amp;.gsub(/ /, &#39;-&#39;)}&quot;.<br>            sub(/\{.*\}/, &quot;&quot;).gsub(/\(|\)/, &quot;-&quot;).gsub(/^-|-$/, &quot;&quot;)<br>          puts &quot;Writing #{name}&quot;<br>          File.open(&quot;#{schemas_path}/#{name}.json&quot;, &quot;w&quot;) { |file| file.write(action.dig(&quot;schema&quot;).to_json) }<br>        end<br>      end<br>    end</pre><pre>    puts &quot;Schemas are ready at #{schemas_path}&quot;<br>  end</pre><p>Executing this task will generate the schemas.json file from the API Blueprint document but it will also split the file into many files, each one containing a schema for a single response. Files will be named with the HTTP Verb, the resource, request name if any, and the HTTP status code for example: GET-Users-200.</p><pre>$ bin/rails api:schemas<br>Generating api schemas from docs/api/documentation.md<br>yarn run v1.7.0<br>$ node_modules/.bin/apib2json --pretty -i docs/api/documentation.md -o test/support/schemas/schemas.json<br>Done in 0.31s.<br>Writing GET-Users-200<br>Writing POST-Users-201<br>Writing POST-Users-422<br>Schemas are ready at test/support/schemas</pre><p>You are ready to start writing tests with Minitest in your Rails application. First, install the <a href="https://github.com/thoughtbot/json_matchers">json_matchers</a> gem in your Gemfile. Configure your test_helper.rb file to load json_matchers.</p><pre>require &#39;json_matchers/minitest/assertions&#39;</pre><pre>JsonMatchers.schema_root = &#39;test/support/schemas&#39;<br>Minitest::Test.send(:include, JsonMatchers::Minitest::Assertions)</pre><p>Then create an integration test for a UsersController and add the following tests to verify all the three responses are documented in the API Blueprint file.</p><pre>require &#39;test_helper&#39;</pre><pre>class UsersApiTest &lt; ActionDispatch::IntegrationTest<br>  test &#39;Users List&#39; do<br>    get &#39;/users&#39;, headers: { Accept: &#39;application/vnd.api-test.v1+json&#39; }</pre><pre>    assert_response :success<br>    assert_matches_json_schema response, &#39;GET-Users-200&#39;<br>  end</pre><pre>  test &#39;Create new User successfully&#39; do<br>    post &#39;/users&#39;, headers: { Accept: &#39;application/vnd.api-test.v1+json&#39; }, params: user_payload</pre><pre>    assert_response :created<br>    assert_matches_json_schema response, &#39;POST-Users-201&#39;<br>  end</pre><pre>  test &#39;Fails to create new User&#39; do<br>    post &#39;/users&#39;, headers: { Accept: &#39;application/vnd.api-test.v1+json&#39; },<br>                   params: user_payload(email: nil, first_name: nil)</pre><pre>    assert_response :unprocessable_entity<br>    assert_matches_json_schema response, &#39;POST-Users-422&#39;<br>  end</pre><pre>  def user_payload(attrs = {})<br>    {<br>      email: &#39;user@mail.com&#39;,<br>      first_name: &#39;Jane&#39;,<br>      last_name: &#39;Doe&#39;<br>    }.merge(attrs)<br>  end<br>end</pre><p>The key here is the assertion for a JSON Schema. If your endpoint is not responding with the expected format then you get detailed information from the test telling you what are you missing, what was expected and what was your response.</p><pre>#: failed schema #: &quot;links&quot; wasn&#39;t supplied. <br>---<br>expected<br>{<br>}<br>to match schema &quot;POST-Users-201&quot;: <br>{<br>  &quot;$schema&quot;: &quot;http://json-schema.org/draft-04/schema#&quot;,<br>  &quot;type&quot;: &quot;object&quot;,<br>  &quot;properties&quot;: {<br>    &quot;data&quot;: {<br>      &quot;type&quot;: &quot;array&quot;,<br>      &quot;items&quot;: {<br>...</pre><h3>Conclusion</h3><p>Keeping your API documentation and endopoints in sync can be a daunting task, writing schema files by hand are not fun at all but hopefully, with the tools presented here it will be easy for you and your team to keep everything up to date.</p><p>If you want to check a sample application with everything showed in this post to go <a href="https://gitlab.com/mariochavez/testing-api-blueprint/tree/master">https://gitlab.com/mariochavez/testing-api-blueprint/tree/master</a></p><blockquote><em>Post originally published at </em><a href="https://sipsandbits.com/2018/08/02/keep-your-api-in-shape-with-api-blueprint/">https://sipsandbits.com/2018/08/02/keep-your-api-in-shape-with-api-blueprint/</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dec2f4be6dfb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/michelada-io/keep-your-api-in-shape-with-api-blueprint-dec2f4be6dfb">Keep your API in shape with API Blueprint</a> was originally published in <a href="https://medium.com/michelada-io">michelada.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From the Asset Pipeline to Webpack]]></title>
            <link>https://medium.com/michelada-io/from-the-asset-pipeline-to-webpack-ce5a4bc323a9?source=rss----6aae07d6a13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/ce5a4bc323a9</guid>
            <category><![CDATA[webpacker]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[webpack-3]]></category>
            <dc:creator><![CDATA[Mario Alberto Chávez]]></dc:creator>
            <pubDate>Thu, 07 Jun 2018 16:56:11 GMT</pubDate>
            <atom:updated>2020-05-19T22:46:00.752Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8onICmYwHx2eUF6dEoCl-Q.jpeg" /></figure><h3>POST UPDATES</h3><p>This post content was updated to fix typos and reflect the changes for Webpack support on Rails 6.0 or better. Please visit the updated version at <a href="https://bit.ly/2WOq461">“From the Asset Pipeline to Webpack”</a></p><p>On May 2011 DHH announced at Railsconf a new framework for Rails, The Asset Pipeline. Also, was announced that SCSS and CoffeeScript along with jQuery were to become a default but overall, the recognition that Web Development changed and that it was the time to assign a proper place to this kind of code and to become a first-class citizen in every Rails application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*V1hWYq2eH6fRd7cS.png" /></figure><p>It was a step forward but people complained about the inclusion of SCSS and CoffeeScript as default. The plan moved forward and on August 31st, 2011 <a href="http://guides.rubyonrails.org/3_1_release_notes.html">version 3.1 was released</a>.</p><p>In the Rails world, the frontend development was mostly HTML/CSS and plugins of jQuery, a lot of them, and more complex UI were done with <a href="http://backbonejs.org/">Backbone.js</a></p><p>Managing, invalidating, and serving assets was a difficult task and <a href="http://guides.rubyonrails.org/asset_pipeline.html">the Asset Pipeline</a> came with the promise to make it easy.</p><p>Frontend development continued moving forward eventually, Backbone.js died and for many applications, jQuery was not enough anymore.</p><p><a href="https://nodejs.org/en/">Node.js</a> and <a href="https://www.npmjs.com/">NPM</a> influenced how frontend was done. Single page applications became a thing, this had a direct effect in the Rails world where it was not easy, anymore, to just download a Javascript file, put it in the vendor folder, and expect it to work.</p><p><a href="https://github.com/rails/sprockets">Sprockets</a>, the heart of the Asset Pipeline, tried to keep up but somehow it fell short. In some client projects, I had the chance to work on solutions that included Gulp, Grunt, and Bower that tried to fill up where Sprockets failed; and it was no joy.</p><p>Finally, to address this situation, on April 27th, 2017 <a href="https://sipsandbits.com/2017/03/09/whats-new-in-rails-51/">Rails 5.1</a> was released, it included Yarn to manage Javascript dependencies and support for <a href="https://webpack.js.org/">Webpack</a> with sensitive defaults and integration into Rails itself via <a href="https://github.com/rails/webpacker">Webpacker</a>.</p><p>Rails provided a tool that is familiar to developers that work with frontend on top of other technologies but to keep compatibility the Asset Pipeline was not removed, actually, you can use Webpacker and the Asset Pipeline seamlessly. It may take a few more versions before the Asset Pipeline becomes deprecated but it might be a good time to give it a try to Webpack.</p><h3>Starting with Webpack.</h3><p>If you are creating a new Rails application starting with Webpack is easy.</p><pre>$ rails new sample_app --webpack</pre><p>This command sets up Rails to use Webpack. If you need something like React, Angular, Elm, or Vuejs set up then you can specify that while creating the application.</p><pre>$ rails new sample_app --webpack=react</pre><p>If you want to disable the Asset Pipeline run the command with the following flag.</p><pre>$ rails new sample_app --webpack --skip-sprockets</pre><p>The --webpack flag will install the Webpacker gem, but will also add configuration for Webpack, a starting point to get into coding as soon as possible. Webpack configuration exists in the /configfolder.</p><pre>config/webpacker.yml<br>config/webpack<br>├── development.js<br>├── environment.js<br>├── production.js<br>└── test.js</pre><p>Assets for Webpack live in /app/javascript/packs. Everything is organized in packs which are analog to having different sets of manifests with the Asset Pipeline but in this case, a pack encloses Javascript, CSS, Images, and any other asset to be sent to the client.</p><p>The default pack is application.js and it is the entry point for Webpack resources, this file is where you require Javascripts, Stylesheets, Images, and everything else. For it, I would normally create an application folder with subfolders for each kind of resource.</p><pre>app/javascript<br>├── application<br>│   ├── images<br>│   ├── javascripts<br>│   └── stylesheets<br>└── packs</pre><p>To use the pack in your HTML, Webpacker provides a couple of handy helpers.</p><pre>&lt;%= javascript_pack_tag &quot;application&quot; %&gt;<br>&lt;%= stylesheet_pack_tag &quot;application&quot; %&gt;</pre><p>Running the Rails server, in development mode, and visiting a page will start a Webpack process to compile the required packs delaying the response from the server. Compiling assets this way is simple but very slow. A faster approach is running a separate Webpack process, this can be done by executing the Webpack server as follow.</p><pre>$ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server</pre><p>Running Webpack this way makes compilation fast and also it will auto reload the current page if assets were modified. Just be aware that if you are running Rails 5.2 the following line needs to be added to config/initializers/content_security_policy.rb inside the policy block.</p><pre>policy.connect_src :self, :https, &#39;http://localhost:3035&#39;, &#39;ws://localhost:3035&#39; if Rails.env.development?</pre><h3>Moving from the Asset Pipeline to Webpack</h3><p>Everything described in the previous section applies to new Rails applications but what about an existing application? The same applies but you need to install Webpack manually, sort of.</p><p>Before continuing, I want to make it clear that if your Javascript does not follow the <a href="https://nodejs.org/api/modules.html">Node.js Modules</a> <a href="https://darrenderidder.github.io/talks/ModulePatterns/#/">pattern</a> you will need to figure out how to change your code to make it Webpack friendly.</p><p>First, add the Webpacker gem to your Gemfile and run Bundler. Now install it with the following command line.</p><pre>$ bin/rails g webpacker:install</pre><p>This will setup Webpack as described before, it will also add the application pack. Now install the <a href="https://github.com/usabilityhub/rails-erb-loader">rails-erb-loader</a> it will become very handy to sprinkle some Ruby into the Javascript files.</p><pre>$ rails webpacker:install:erb</pre><p>Once erb loader is installed, rename file app/javascript/packs/application.js to app/javascript/packs/application.js.erb</p><p>If you load your application in the browser, even when the pack file is empty, Webpack will fail.</p><pre>ERROR in ./app/javascript/packs/application.js.erb<br>Module build failed: Error: rails-erb-loader failed with code: 1</pre><p>The problem is that your application.js.erb now understand Ruby, but comments in the file include something like this.</p><pre>// To reference this file, add &lt;%= javascript_pack_tag &#39;application&#39; %&gt; to the appropriate<br>// layout file, like app/views/layouts/application.html.erb</pre><p>Just add another % to the start of the declaration to become</p><pre>&lt;%%= javascript_pack_tag &#39;application&#39; %&gt;</pre><p>The next step in this migration will be to move all your Javascript files from app/assets/javascripts to app/javascript/application/javascripts. Rename the newly copied application.js to index.js.erb.</p><p>Also, move your Stylesheets and Images to their folder in app/javascript/application. Add an empty index.js.erb to each folder.</p><p>For images open the newly added index.js.erb and import all the images there.</p><pre>import &#39;image1.png&#39;;<br>import &#39;image2.png&#39;;<br>...<br>import &#39;imageN.png&#39;;</pre><p>You can add files one by one or take advantage of Ruby and do something like this.</p><pre>&lt;% images_glob = Rails.application.root.join(&#39;app&#39;, &#39;javascript&#39;, &#39;application&#39;, &#39;images&#39;, &#39;**&#39;, &#39;*.{png,svg}&#39;) %&gt;<br>&lt;% Dir.glob(images_glob).each do |image| %&gt;<br>  import &#39;&lt;%= image %&gt;&#39;;<br>&lt;% end %&gt;</pre><p>That was easy, now look into your Rails views and update your code to use the asset_pack_path helper everywhere you have a reference to an image.</p><pre>&lt;%= image_tag asset_pack_path(&quot;application/images/image1.png&quot;) %&gt;</pre><p>Note that the complete path of the image is required, in this case, application/images.</p><p>Also in your Stylesheets file be sure to replace the image_url helper for just url and update images references to have the complete path.</p><p>Now it is time to work with your Stylesheets. If you have an application.css it is likely that you are requiring your Stylesheets with Sprocket comments syntax, remove it from your application.css and open the index.js.erb in your Stylesheets folder.</p><p>In your index file, you can import each Stylesheet file, one by one.</p><pre>import &#39;application.css&#39;;<br>import &#39;layout.css&#39;;<br>...<br>import &#39;buttons.css&#39;;</pre><p>Or you can use Ruby, as we did it for images, and import all available files.</p><pre>&lt;% css_glob = Rails.application.root.join(&#39;app&#39;, &#39;javascript&#39;, &#39;application&#39;, &#39;stylesheets&#39;, &#39;**&#39;, &#39;*.{css}&#39;) %&gt;<br>&lt;% Dir.glob(css_glob).each do |file| %&gt;<br>  import &#39;&lt;%= file %&gt;&#39;;<br>&lt;% end %&gt;</pre><p>Also if you have any gem that provides Stylesheets you can import them as follow.</p><pre>import &quot;&lt;%= File.join(Gem.loaded_specs[&#39;mygem&#39;].full_gem_path, &#39;app&#39;, &#39;assets&#39;, &#39;stylesheets&#39;, &#39;myfile.css&#39;) %&gt;&quot;;</pre><p>When you need to import more than one file from the gem then create an array with the name of each file and iterate over it for import.</p><p>If you are using SCSS, then your application file might be called application.scss, in this case, imports will happen with SCSS syntax which is ok. Just import your application.scss into index.js.erb and you will be fine.</p><pre>import &#39;application.scss&#39;;</pre><p>If you are using a CSS/SCSS framework via a gem, you better remove the gem and install it via NPM with Yarn. The following example installs <a href="https://bulma.io/">Bulma</a>.</p><pre>$ bin/yarn add bulma</pre><p>Then add @import &#39;~bulma/bulma&#39;; into your application.scss.</p><p>The final step is to migrate your Javascript assets. Update your index.js.erb file to import all dependencies declared originally for Sprockets using the require comments, now dependencies will be resolved by Yarn.</p><p>For example, here we are adding the common Javascript dependencies.</p><pre>$ bin/yarn add  jquery turbolinks rails-ujs activestorage</pre><p>Now in the top of your index.js.erb import them as follow.</p><pre>import Rails from &#39;rails-ujs&#39;;<br>import Turbolinks from &#39;turbolinks&#39;;<br>import * as ActiveStorage from &#39;activestorage&#39;;</pre><pre>Rails.start();<br>Turbolinks.start();<br>ActiveStorage.start();</pre><p>For other libraries read the README file for additional information on how to import them.</p><p>In the case of jQuery, you must make it available with $ and jQuery. Open the config/webpack/environment.js file and add the following lines just above module.exports = environment.</p><pre>const webpack = require(&#39;webpack&#39;);<br>environment.plugins.append(&#39;Provide&#39;, new webpack.ProvidePlugin({<br>  $: &#39;jquery&#39;,<br>  jQuery: &#39;jquery&#39;<br>}))</pre><p>For Ruby gems that includes Javascript, it might vary how to import them but for many, it will be as easy as importing the files from the gem.</p><pre>import &quot;&lt;%= File.join(Gem.loaded_specs[&#39;mygem&#39;].full_gem_path, &#39;app&#39;, &#39;assets&#39;, &#39;javascripts&#39;, &#39;myfile&#39;) %&gt;&quot;;</pre><p>We can use the same technique showed where an iteration is made to load the files.</p><pre>&lt;% [&#39;file1&#39;, &#39;file2&#39;].each do |file| %&gt;<br> import &quot;&lt;%= File.join(Gem.loaded_specs[&#39;mygem&#39;].full_gem_path, &#39;app&#39;, &#39;assets&#39;, &#39;javascripts&#39;, file) %&gt;&quot;;<br>&lt;% end %&gt;</pre><p>For our own files, again you can use the same technique used with Images or Stylesheets.</p><pre>&lt;% files_glob = Rails.application.root.join(&#39;app&#39;, &#39;javascript&#39;, &#39;application&#39;, &#39;javascripts&#39;, &#39;**&#39;, &#39;*.js&#39;) %&gt;<br>&lt;% Dir.glob(files_glob).each do |file| %&gt;<br>  import &#39;&lt;%= file %&gt;&#39;;<br>&lt;% end %&gt;</pre><p>Now modify the application.js.erb file inside the packs folder to reference the index.js.erb file for all assets.</p><pre>import &#39;../application/images/index.js.erb&#39;;<br>import &#39;../application/stylesheets/index.js.erb&#39;;<br>import &#39;../application/javascripts/index.js.erb&#39;;</pre><p>If everything is ok then Webpack will compile the assets and your application will load normally. If not, then it would be time to debug any messages and try to fix it.</p><p>You would want to disable the Asset Pipeline in your application, to do this remove all configuration settings related to config.assets in config/environments/production.rb and config/environments/development.rb. Also, remove the config/initializer/assets.rb file. From your Gemfile remove gems coffee-rails, sass-rails, uglifier, and turbolinks.</p><p>At the top of your config/application.rb remove the require &quot;rails/all&quot; and expand the framework requires and comment the require for &quot;sprockets/railtie&quot;.</p><pre>require &quot;rails&quot;<br># Pick the frameworks you want:<br>require &quot;active_model/railtie&quot;<br>require &quot;active_job/railtie&quot;<br>require &quot;active_record/railtie&quot;<br>require &quot;active_storage/engine&quot;<br>require &quot;action_controller/railtie&quot;<br>require &quot;action_mailer/railtie&quot;<br>require &quot;action_view/railtie&quot;<br># require &quot;action_cable/engine&quot;<br># require &quot;sprockets/railtie&quot;<br>require &quot;rails/test_unit/railtie&quot;</pre><p>Remove your app/assets folder.</p><h3>Conclusion</h3><p>If you get to this part of the blog and your application is running with Webpack for your assets: congratulations! Your team now has modern tools to work on your frontend.</p><p>If you still have errors you might need to tweak things related to your assets and maybe it would be a good idea to not disable the Asset Pipeline yet and continue working on your migration to Webpacker.</p><p>An additional bonus: You can use foreman to start the Rails server and Webpack server with one command. Install the foreman gem with gem install foreman, don’t add it to your Gemfile.</p><p>Then create a Procfile in your Rails root with the following lines.</p><pre>web: bin/rails s -p $PORT<br>webpack: bin/webpack-dev-server</pre><p>Now start your servers with PORT=3200 foreman start. Note PORT can be any port of your choice.</p><blockquote>Post originally published at <a href="https://sipsandbits.com/2018/06/07/from-the-asset-pipeline-to-webpack/">https://sipsandbits.com/2018/06/07/from-the-asset-pipeline-to-webpack/</a></blockquote><p><strong><em>Photo by </em></strong><a href="https://unsplash.com/photos/vWsubsaym3o"><strong><em>Aral Tasher</em></strong></a><strong><em> on Unsplash</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce5a4bc323a9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/michelada-io/from-the-asset-pipeline-to-webpack-ce5a4bc323a9">From the Asset Pipeline to Webpack</a> was originally published in <a href="https://medium.com/michelada-io">michelada.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in Rails 5.1]]></title>
            <link>https://medium.com/michelada-io/whats-new-in-rails-5-1-fb0bab9c42e0?source=rss----6aae07d6a13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/fb0bab9c42e0</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Mario Alberto Chávez]]></dc:creator>
            <pubDate>Wed, 04 Oct 2017 16:40:02 GMT</pubDate>
            <atom:updated>2017-03-09T17:58:21.636Z</atom:updated>
            <content:encoded><![CDATA[<p>This was originally posted on <a href="http://blog.michelada.io/whats-new-in-rails-51">http://blog.michelada.io/whats-new-in-rails-51</a></p><p>Rails 5.1 beta 1 was just <a href="http://weblog.rubyonrails.org/2017/2/23/Rails-5-1-beta1/">announced</a> by the Rails team and it includes important changes on how Javascript will be used by Rails applications , it even says ”Loving JavaScript” in the section title to describe these changes. This is probably the biggest change since the Asset Pipeline was introduced in Rails 4.0. It also acknowledges how modern web applications are being built in the present.</p><h3>Ruby 2.4 support</h3><p>This new version of Rails is compatible with Ruby 2.4, for cases where Ruby 2.4 provides methods defined in ActiveSupport core extensions, Ruby’s implementation will be favored, if you are running Rails with the previous version of Ruby then the ActiveSupport core extension code will be used.</p><p>An example of this is Hash#compact and Hash#compact!. Also, Rails 5.1 supports Ruby’s unification of Fixnum and Bignum into the Integer class. Unicode version 9.0.0 from Ruby 2.4 is available as well, so now you have more emojis to name your controller and models.</p><h3>Removed deprecated functionality</h3><p>It couldn’t be a new Rails release without removing deprecated code or marking code as deprecated.</p><h3>ActiveRecord</h3><p>Following methods have been removed #uniq, #uniq!, #uniq_value, #insert_sql, #update_sql, and #delete_sql.</p><p>If you use fixtures #use_transactional_fixtures has been removed as well.</p><p>The following rake db tasks were also removed db:test:clone, db:test:clone_schema,db:test:clone_structure`.</p><h3>ActionPack</h3><p>Don’t call env anymore from your controllers, since ActionController::Metal#env was removed, use request instead.</p><p>If you are doing Integration tests, ActionDispatch::IntegrationTest now requires you to use the Keyword arguments versions of #get, #post, #patch, #put, #delete, and #head.</p><p>In your controller you can’t userender :text or :nothing anymore. Also redirect_to doesn’t support the :back option anymore.</p><p>Controller methods skip_action_callback, skip_filter, before_filter, prepend_before_filter, skip_before_filter, append_before_filter, around_filter, prepend_around_filter, skip_around_filter, append_around_filter, after_filter, prepend_after_filter, skip_after_filter and append_after_filter were removed too.</p><h3>Railties</h3><p>rake tasks rails:update, rails:template, rails:template:copy, rails:update:configs and rails:update:bin were removed.</p><p>Configuration options config.serve_static_files and config.static_cache_control were also removed .</p><h3>So, what is new?</h3><p>Here is the list of features that you can expect with the new release.</p><h3>Adiós jQuery</h3><p>If you have been in Rails world for a while, you probably remember the time when <a href="http://blog.michelada.io/script.aculo.us">Scriptaculous</a> was replaced by jQuery, well now is time to say Adiós to jQuery.</p><p>Rails doesn’t depend on jQuery anymore, rails-ujs was rewritten to be plain vanilla Javascript. You can still add jQuery as a dependency in your app but is not installed by default with new Rails applications.</p><h3>New way to work with Javascript.</h3><p>The Javascript world has changed a lot since Rails 4.0 introduced the Asset Pipeline. Now it is almost impossible to simply download a Javascript library from its Git repository, place it under vendor/assets/javascripts, require it in the application.js manifest and expect it to work.</p><p>Today, Javascript libraries are packed for Node.js and configured to work with Node’s module loading system making impossible for Rails to work with them without additional configuration to include Node.js and npm into the picture.</p><p>Rails team acknowledges this and with Rails 5.1 they made it easy for us to work with the Javascript world with the introduction of <a href="https://yarnpkg.com/en/">Yarn</a>.</p><p>Every new Rails application will include Yarn, which is a package manager for Javascript. To use Yarn you must install it first if you don’t already have it. In MacOS, you can just use Homebrew.</p><pre>$ brew install yarn</pre><p>This command will install Yarn and Nodejs. By creating a new Rails application with Rails 5.1.0 a new binstub, yarn, will be placed in the bindirectory. You should always use this binstub when working with Yarn from a Rails application.</p><p>To add a Javascript package to your Rails app, you simply use the add command inYarn.</p><pre>$ bin/yarn add moment</pre><p>Yarn will create a package.json and yarn.lock files, it will also download the Javascript package into node_modules directory. Yarn will manage versions and dependencies for us.</p><p>Once a Javascript package has been installed you can reference it from the Asset Pipeline manifest. In this example, to use the moment library, you can require it by adding the following line in application.js:</p><pre>//= require moment/moment</pre><p>Then you’re free to use it on your own Javascript files. By running rails assets:precompile your generated application-{digest}.js file will include the moment library.</p><p>If you are into single page applications, Rails now comes with setup options for React, Angular, and Vue. In this case, Rails depends on <a href="https://webpack.github.io/">Webpack</a> to manage modules and dependencies.</p><p>To setup Webpack, Rails depends on the gem <a href="https://github.com/rails/webpacker">Webpacker</a> which setups required configuration for Webpack to work with Rails.</p><p>To start a Rails/React project you can run the command:</p><pre>$ rails new single_page --webpack=react</pre><p>For an existing project, run the following command but first add the web packer gem in your Gemfile. As of today, it is better if you pull the gem directly from its repository.</p><blockquote><em>Webpacker gem is compatible with Rails 4.2 or better.</em></blockquote><pre>$ rails webpacker:install<br>$ rails webpacker:install:react</pre><p>The first command will setup Webpack for development and production environments, this configuration can be found in config/webpack and it is a standard Webpack configuration, something that you might expect by using Webpack in a standalone or Nodejs application.</p><p>Two new stubs are added to the bin directory: webpack-watcher and webpack-dev-server, both of them are scripts that need to be running in development along with rails s. The first one is a watcher that will automatically recompile your Javascript as you make changes. The second one does the same but it supports advanced features of Webpack. The later runs on http://localhost:8080 and you need to configure the option config.x.webpacker[:dev_server_host] in your config/environments/development.rb to allow rails to serve Javascript files properly. Only one of the scripts needs to be running at a time.</p><p>Your Javascript code must be placed in app/javascript, in there you must define packs, a pack is a Javascript application, it needs to have an entry point like signup.js and a directory app/javascript/signup must exist with all related files to this application.</p><p>Then in your Rails layout, you just add the javascript_pack_tag to load your application.</p><p>&lt;%= javascript_pack_tag ‘signup’ %&gt;</p><p>javascript_pack_tag will reference your pack and in production mode it will insert the digested file.</p><p>If you need to reference Sprockets files in your Javascript packs, just add the .erb extension to your file, include the helpers and use them.</p><pre>// app/javascript/signup/form.js.erb</pre><pre>&lt;% helpers = ActionController::Base.helpers %&gt;<br>var logoPath = &quot;&lt;%= helpers.image_path(&#39;logo.png&#39;) %&gt;&quot;;</pre><p>rails webpacker:install:react command tells Yarn to setup decencies to use React in your application but you can also pass angular or vue as parameters.</p><p>Once you are ready to deploy your application just run the following commands to compile all your assets and Javascripts.</p><pre>$ rails asset:precompile<br>$ rails webpacker:compile</pre><p>Now is up to you to decide if you just need Yarn or if you want to include Webpack into your development environment. Rails and Asset Pipeline will not get in your way.</p><h3>Keep your secrets safe.</h3><p>It is a very common practice to keep your production secrets in environment variables, the ones that later are loaded from secrets.ymlwhen you boot your Rails application. Another approach is to set your private keys in your secrets.yml and exclude it from your source control while keeping a separate file for production. Either way has its pros and cons.</p><p>Rails now include a way to encrypt your secrets file. To use encrypted secrets you need to setup your project first by running:</p><pre>$ bin/rails secrets:setup</pre><p>This will generate a config/secrets.yml.key which will have the encryption key, you need to secure this file and don’t add it to your source control system. A new file config/secrets.yml.enc will be added, this is the encrypted file that will keep your secrets safe.</p><p>If you need to change a value, you will need to run the command:</p><pre>$ bin/rails secrets:edit</pre><p>This will open your default editor and will allow you to make changes to your encrypted file. The structure of this file is the same as config/secrets.yml, once you make your changes and save the file, everything will be encrypted again.</p><p>To tell Rails to use this encrypted file instead the regular config/secrets.ymlyou will need to modify your config/production.rb file to include the line config.read_encrypted_secrets = true.</p><p>From now on, when you deploy your application to a production environment and given that config/secrets.yml.enc is checked in your source control, just set the environment variable RAILS_MASTER_KEY with the encryption key.</p><p>The cryptography method used by Rails was reported to be <a href="https://github.com/rails/rails/issues/28135">weak</a>, but it was quickly updated to use a <a href="https://github.com/rails/rails/pull/28139">stronger</a> method.</p><h3>Direct and resolve routes</h3><p>Rails now allow you to define custom URLs that override or replace default behavior.</p><p>The first example of this is direct, which allows us to define custom URLs like</p><pre>direct(:dev_shop) { &quot;https://michelada.io&quot; }</pre><p>Which we can use in our code like:</p><pre>&lt;%= link_to &quot;michelada.io&quot;, dev_shop_url %&gt; #=&gt; &lt;a href=&quot;https://michelada.io&quot; /&gt;</pre><p>You can also define routes to polymorphic models using an array definition like:</p><pre>direct :model_section do |model|<br>  [model, anchor: &quot;#{model.model_name.singular}_#{model.id}&quot;]<br>end</pre><p>And then use the helper as follow:</p><pre>&lt;%= link_to &quot;User section&quot;, user_section_path(@user) %&gt; #=&gt; &lt;a href=&quot;/users/1#user_1&quot;&gt;User section&lt;/a&gt;</pre><p>Also, you can pass a hash with controller and action as direct’s block.</p><pre>direct :current_users do<br>  { action: &quot;index&quot;, controller: &quot;users&quot;, active: true }<br>end</pre><pre>&lt;%= link_to &quot;Current users&quot;, current_users_path %&gt; #=&gt; &lt;a href=&quot;/users?active=true&quot;&gt;Current users&lt;/a&gt;</pre><p>direct can also have default parameters like:</p><pre>direct :browse, page: 1, page_size: 10 do |klass, options|<br> [ klass, options ]<br>end</pre><pre>&lt;%= link_to &quot;Browse users&quot;, browse_path(:users) %&gt; #=&gt; &lt;a href=&quot;/users?page=1&amp;amp;page_size=10&quot;&gt;Browse users&lt;/a&gt;<br>&lt;%= link_to &quot;Browse users&quot;, browse_path(:users, page: 2) %&gt; #=&gt; &lt;a href=&quot;/users?page=2&amp;amp;page_size=10&quot;&gt;Browse users&lt;/a&gt;</pre><p>resolve helps us map a model to a resource. Here is an example for the Usermodel being mapped to theprofile resource.</p><pre>resource :profile<br>resolve(&quot;User&quot;) { [:profile] }</pre><p>By doing this mapping, we are telling to the router to not use paths based on the model name, but resolve it to profile. Doing this when you write the following code will generate the correct resource paths.</p><pre>&lt;%= link_to @user.name, @user %&gt; #=&gt; &lt;a href=&quot;/profile&quot;&gt;Sample user&lt;/a&gt;</pre><pre>&lt;%= form_with model: User.new do |f| %&gt;<br>  &lt;%= f.text_field :name %&gt;<br>&lt;% end %&gt;<br>#=&gt;<br>&lt;form action=&quot;/profile&quot; accept-charset=&quot;UTF-8&quot; data-remote=&quot;true&quot; method=&quot;post&quot;&gt;&lt;input name=&quot;utf8&quot; type=&quot;hidden&quot; value=&quot;✓&quot;&gt;<br>  &lt;input type=&quot;text&quot; name=&quot;user[name]&quot;&gt;<br>&lt;/form&gt;</pre><p>Both direct and resolve work on the global scope of the routes, they can’t be used inside a scope or namespace.</p><h3>form_for and form_tag unified into form_with</h3><p>form_for and form_tag in Rails were very similar, both allowed you to create a form tag but the first one uses model’s attributes to build create or update form, while the second one simply create an HTML form tag with the passed URL as action.</p><p>Given their similarities, with Rails 5.1 both were unified into form_with. If we want to create a form based on model attributes you just need to pass the model: param.</p><pre>&lt;%= form_with model: User.new do |user| %&gt;<br>  &lt;%= user.text_field :name %&gt;<br>&lt;% end %&gt;<br>#=&gt;<br>&lt;form action=&quot;/profile&quot; accept-charset=&quot;UTF-8&quot; data-remote=&quot;true&quot; method=&quot;post&quot;&gt;&lt;input name=&quot;utf8&quot; type=&quot;hidden&quot; value=&quot;&amp;#x2713;&quot;/&gt;<br>  &lt;input type=&quot;text&quot; name=&quot;user[name]&quot; /&gt;<br>&lt;/form&gt;</pre><p>If you just want a form without the model’s attribute, just pass the url: param.</p><pre>&lt;%= form_with url: &quot;/users&quot; do %&gt;<br>  &lt;%= text_field_tag :name %&gt;<br>&lt;% end %&gt;<br>#=&gt;<br>&lt;form action=&quot;/user&quot; accept-charset=&quot;UTF-8&quot; data-remote=&quot;true&quot; method=&quot;post&quot;&gt;&lt;input name=&quot;utf8&quot; type=&quot;hidden&quot;value=&quot;&amp;#x2713;&quot; /&gt;<br>  &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; /&gt;<br>&lt;/form&gt;</pre><p>form_with accepts the same parameters as form_for and form_tag for scopes, data attributes, HTML attributes, method, etc.</p><p>With form_with be aware that the data-remote attribute is set to true by default. The syntax for nested models was also changed. Instead of using fields_for you must use now the fields method and set model: param with the nested model instance.</p><pre>&lt;%= form_with model: User.new do |user| %&gt;<br>  &lt;%= user.text_field :name %&gt;<br>  &lt;%= user.fields model: Profile.new do |profile| %&gt;<br>    &lt;%= profile.text_field :age %&gt;<br>  &lt;% end %&gt;<br>&lt;% end %&gt;<br>#=&gt;<br>&lt;form action=&quot;/profile&quot; accept-charset=&quot;UTF-8&quot; data-remote=&quot;true&quot; method=&quot;post&quot;&gt;&lt;input name=&quot;utf8&quot; type=&quot;hidden&quot; value=&quot;✓&quot;&gt;<br>  &lt;input type=&quot;text&quot; name=&quot;user[name]&quot;&gt;</pre><pre>    &lt;input type=&quot;text&quot; name=&quot;user[profile][age]&quot;&gt;<br>&lt;/form&gt;</pre><h3>System tests</h3><p>There is a good chance that you are currently using <a href="https://github.com/teamcapybara/capybara">Capybara</a> for your features or acceptance testing in your Rails applications. Using it currently involves setting up Capybara in your project, along with a strategy for cleaning your database with tools like <a href="https://github.com/DatabaseCleaner/database_cleaner">database_cleaner</a>, and <a href="https://github.com/copiousfreetime/launchy">launchy</a> gem to help you to debug when an error happens.</p><p>With Rails embracing Javascript the need to support full testing, including the javascript part, sparked what is called System Tests with Rails 5.1. Now Capybara is setup by default and a change in the framework is included to deal with <a href="https://github.com/rails/rails/pull/28083">transactional fixtures</a> without the need to have something like <a href="https://github.com/DatabaseCleaner/database_cleaner">database_cleaner</a>.</p><p>A new file is included, it is the base for systems tests test/application_system_test_case.rb , this file setups by default use of selenium and chrome driver to run your test.</p><pre>require &quot;test_helper&quot;</pre><pre>class ApplicationSystemTestCase &lt; ActionDispatch::SystemTestCase<br>  driven_by :selenium, using: :chrome, screen_size: [1400, 1400]<br>end</pre><p>You can change the parameters passed to driven_by to use firefox or to use a headless server like poltergeist. Capybara DSL and assertions are available in your system tests. You can create these tests files by hand our use rails’ generator rails g test_unit:system</p><pre>require &quot;application_system_test_case&quot;</pre><pre>class UsersTest &lt; ApplicationSystemTestCase<br>  test &quot;visiting the index&quot; do<br>    visit root_url</pre><pre>    assert_selector &quot;h1&quot;, text: &quot;Hello Rails&quot;<br>  end<br>end</pre><p>When a system test fails, a screenshot is taken and saved into tmp directory, minitest will report the file that contains the screenshot for you to review.</p><pre>[Screenshot]: tmp/screenshots/failures_test_visiting_the_index.png</pre><h3>Conclusions</h3><p>Probably the feature that stands out in this new version, is the change on how Rails deals with Javascript and npm. Like I mentioned earlier, this acknowledges how web development has changed over time, but also states that using Rails to build web applications is still an option, no matter if your application is HTML, an API or a Javascript single page application.</p><p>Rails is removing all the friction and helping you to design and build the kind of application that makes sense for your immediate needs.</p><p>This new version might be released this same year, probably around the <a href="http://railsconf.com/">Railsconf</a>, which is relevant not only because you want to use the new features, but because version 4.2.x might become unsupported. This might be a good time to start planning the upgrade in your applications.</p><p>If you need help on how to upgrade older versions of Rails, please refer to our previous blog post “<a href="http://blog.michelada.io/upgrading-a-ruby-on-rails-application">Upgrading a Ruby on Rails application</a>”.</p><blockquote><em>Thanks to David Padilla and Gil Villa for helping to review this post content.</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb0bab9c42e0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/michelada-io/whats-new-in-rails-5-1-fb0bab9c42e0">What’s new in Rails 5.1</a> was originally published in <a href="https://medium.com/michelada-io">michelada.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upgrading a Ruby on Rails application]]></title>
            <link>https://medium.com/michelada-io/upgrading-a-ruby-on-rails-application-a3856d63c506?source=rss----6aae07d6a13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/a3856d63c506</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Mario Alberto Chávez]]></dc:creator>
            <pubDate>Wed, 04 Oct 2017 16:39:43 GMT</pubDate>
            <atom:updated>2017-02-16T17:59:25.612Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post was originally posted at </em><a href="http://blog.michelada.io/upgrading-a-ruby-on-rails-application"><em>http://blog.michelada.io/upgrading-a-ruby-on-rails-application</em></a></p><p>Not every Ruby on Rails application that we work on at <a href="https://michelada.io/">michelada.io</a> is a Rails application running in the latest version, I’ll say that probably 70% are still running on Ruby on Rails 4.2, 25% are running on Rails 5 and the rest on Rails 3.2.</p><p>Rails 5 numbers are for applications that we have started for our clients since the Rails team released the first beta of version 5 in 2015.</p><p>For Ruby 4.2 applications, are applications that we started for our clients before Rails 5 beta or applications that our clients started on their own and we have taken ownership or we are collaborating with its engineering team to support and adding new features.</p><blockquote><em>Both versions as today are still being supported by the Rails team with security patches and bug fixes. Pretty much the same apply with most of the gems that we use in those projects.</em></blockquote><p>Rails 3.2 applications that some our clients still keep around are applications in maintenance mode, means no new big features are added but small tweaks might get into their codebase time to time.</p><p>Applications running in this version are subject to be rewritten from scratch with a newer version of Rails. From our experience with our clients, this happens when the core logic of the application is what the client wants but everything else is not that important, like converting the application to be an API only with the base logic.</p><p>The other case is when a client asks to perform an upgrade from 3.2 to 5. This just happened in my last/current project and I want to talk in this post.</p><h3>Why upgrade your Rails application?</h3><p>Reasons on why you might want to upgrade your application may vary case by case. It might not be driven because of business needs but primary due to technical needs or concerns.</p><h3>Security and bug fixes</h3><p>Security is a critical reason to decide to perform an upgrade, this is not only a technical issue but business also; no one wants to deal with a problem where your user’s information might be compromised.</p><p>Rails and Ruby have a very similar maintenance policy where only the latest release of a series will be maintained.</p><p><a href="http://guides.rubyonrails.org/maintenance_policy.html">For Rails</a>, currently, this means 4.2 and 5.0. Version 4.1 was maintained by a special effort of <a href="https://twitter.com/rafaelfranca">Rafael França</a> but once that Rails 5.1 is released — possible this 2017 — there is no word if 4.2 will be maintained in the same way that 4.1 was.</p><p>Ruby 2.4 was released last December and along with Ruby 2.3 are still under <a href="https://bugs.ruby-lang.org/projects/ruby/wiki/GeneralMaintenancePolicy">maintenance policy</a>, as today there is no word on End of Life of Ruby 2.2, on Ruby’s repository looks like bug fixes are still being backported to this version.</p><p>Even if you are at the latest version of your stack, you still need to ensure that your infrastructure and your code are secure. There are mailing lists for <a href="https://groups.google.com/forum/#!forum/ruby-security-ann">Ruby</a> and <a href="https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-security">Ruby on Rails</a> where you can find out and follow Common Vulnerabilities and Exposures or CVE.</p><p>In your project you must have a policy on how often update versions of your dependency Gems, vulnerabilities exposures are also discovered on them. You can check every gem manually but if you want an automated solution to help you, use <a href="https://github.com/rubysec/bundler-audit">bundler-audit</a>, it will work with your Gemfile to report any CVE in your dependencies.</p><p>Your own code might be also subject to vulnerabilities, <a href="http://brakemanscanner.org/">Brakeman</a>, which is a security scanner, might help you to discover insecure patterns in your code, also <a href="http://gavinmiller.io/">Gavin Miller’s blog</a> is a great resource to learn how to write more secure code.</p><p>Being in the latest version in your stack will also help your team to avoid to have workaround code fix a bug, maybe, already fixed in latest versions. Doing workarounds makes harder to understand why that code exists, it might also introduce new bugs.</p><h3>Performance</h3><p>While always is nice to have our applications running as fast as possible, maybe not receiving this kind of updates will not degrade your performance but you will be missing the opportunity of a faster application without a change in your code, just by being the latest version of your stack.</p><p>Many improvements have been introduced to Rails and Ruby in their latest versions to reduce object allocations, code optimization and in general to have Ruby applications to perform better.</p><h3>Ok, you said that this post was about how to upgrade a rails 3.2 application to Rails 5.0</h3><p>Now going back to the main subject of this post a client handed me a Rails 3.2 project, they wanted to add new functionality, convert the application to be an API only and upgrade it to the latest version possible.</p><p>I will not go into a step by step migration process because it might be different for each project but here is a list of things that you need to watch out to have a successful migration.</p><h3>Test suite</h3><p>When you are new to a Rails application codebase, the first place to check is always project’s automated tests. In the case of this application, it had RSpec 2.x specs but 50% of the specs were failing, not a good start point.</p><p>Given that required new functionality was a priority I decided to go ahead and implement it, the only thing that I did before startiing the process, was to upgrade RSpec from version 2.x to version 3.x. Now besides failing specs, I had a bunch of warnings because of the should syntax of RSpec 2.x.</p><p>I implemented the new functionality while adding new specs and fixing the ones failing that were related to what I was working on, at the same time I was updating RSpec syntax.</p><p>Also, project specs were using <a href="https://github.com/notahat/machinist">machinist</a> as test data factory. Machinist is no longer maintained and the data model wasn’t really complicated, so I move the project to use <a href="http://guides.rubyonrails.org/testing.html#the-low-down-on-fixtures">Rails Fixtures</a>.</p><p>After new functionality was in place, my next step was to fix remaining failing specs while moving them away from machinist and updating RSpec syntax, also, I converted controller specs to be integration specs.</p><p>Few days laters our test suite was green, and I was ready to start with Rails migration.</p><p>Talking with a co-worker about RSpec syntax migration he told me about <a href="https://github.com/yujinakayama/transpec">transpec</a>which is a gem to help to automate syntax migration, my work here was already done, so I don’t have the chance to try it out.</p><h3>Rails migration</h3><p>With a green test suite, I was ready to start Rails migration. Just for the sake of the test suite, I relaxed versions in Gemfile for all gems and the run a bundle update, next I ran the test suite and it was still green.</p><p>The first step was to modify the Gemfile to add Ruby version, in my case, it was 2.3.1, and also to change Rails version to be 5.0.1. Additionally I changed sass-rails version to be ~&gt; 5.0, coffee-rails to ~&gt; 4.1 and uglifier to &gt;= 1.3.0, also I added puma as dependency. At this point, conversion to be an API only is not done, that is why these gems are still a dependency.</p><p>Then I ran bundle update and it finished without an issue. This might be different depending on the gems that your projects rely on. If specified gem is not compatible with Rails 5 bundler might fails. Probably if I had keep machinist gem this one might cause bundler to fail.</p><p>Configuration settings are something that changes all the time between different versions of Rails. To upgrade configuration settings you need to run rake app:update, this will create new files like cable.yml but also it will try to replace existing files like application.rb, environment.rb, production.rb and so on, but before overwriting the files it will ask you what do you want to do.</p><p>You can skip the file, overwrite it, overwrite all, see a diff or about the operation. On all files I displayed the diff to see changes on file, then I proceed to overwrite the file, open it with an editor and put back what I got from the diff that I wanted to keep like config.autoload_paths += %W(#{config.root}/lib) in application.rb. There were files like boot.rb or en.yml that I just replaced because there was nothing to keep there but also there were files like routes.rb that I skipped from being overwritten.</p><p>After this process was done, I tried to load Rails console, and it loaded with success, but we were not ready to launch the server yet. I ran the test suite and pretty much all specs failed also I did receive many warnings.</p><p>So far all failures and warnings are related to changes in the API between Rails 3.2 and Rails 5. So let’s see what needs to be updated.</p><p>Our routes.rb file have many routes defined with match but no viaparameter was specified, so here we have 2 options: add via parameter or convert match route to a http method, like:</p><pre>match “/share/:id” =&gt; “shares#create”<br># become:<br>match “/share/:id” =&gt; “shares#create”, via: [:post]<br># or<br>post “/share/:id” =&gt; “shares#create”</pre><p>Another required change is the use of <a href="https://github.com/rails/strong_parameters">strong parameters</a> instead of the old and insecure attr_accessible method. Both methods work, mainly with controllers, to define what attributes in a model are subject to mass assignment.</p><p>For example, you can have a model Customer and you want to update its :name and :address from a web form, the way this worked before strong parameters was:</p><pre>class Customer &lt; ActiveRecord::Base<br>  attr_accessible :name, :address<br>end</pre><pre>class CustomersController &lt; ApplicationController<br>...<br>  def update<br>    @customer = Customer.find(params[:id]<br>    if @customer.update_attributes(params[:customer])<br>      return redirect_to customers_path<br>    end<br>   end<br> ...<br> end</pre><p>attr_accesible is not available anymore starting Rails 4.0 because it did prove to be an insecure way to protect your model’s data. The code presented before needs to be updated to:</p><pre>class Customer &lt; ActiveRecord::Base<br>end</pre><pre>class CustomersController &lt; ApplicationController<br>...<br>  def update<br>    @customer = Customer.find(params[:id]<br>    if @customer.update_attributes(edit_params)<br>      return redirect_to customers_path<br>    end<br>  end<br>...<br>  private</pre><pre>  def edit_params<br>    require(:customer).permit(:name, :address)<br>  end <br>end</pre><p>This change needs to be done in all your models and controllers that create or update new records using Rails models.</p><p>ActiveRecord query API also changed and finders functionality was removed. The following queries are example of what was removed from Rails 5:</p><pre>Customer.find(:all, conditions: { active: true }, limit: 10)<br>Customer.find_by_name(&quot;Customer 1&quot;)<br>Customer.find_last_by_active(false)<br>Customer.find_or_initialize_by_name(&quot;Customer 2&quot;)</pre><p>Old hash syntax and dynamic finders need to be updated to use where clause.</p><pre>Customer.where(active: true).limit(10)<br>Customer.where(name: &quot;Customer 1&quot;)<br>Customer.where(active: false).last<br>Customer.find_or_initialize_by(name: &quot;Customer 2&quot;)</pre><p>For more details on the changes to the ActiveRecord query API look at <a href="https://github.com/rails/activerecord-deprecated_finders">deprecated finders</a>.</p><p>After all these changes in the source code the test suite as green again, but still I got a lot of warnings but Rails was complaining because of 2 situations.</p><p>The use of before_filter and skip_before_filter in Rails controllers is deprecated and those methods will be removed in the future. Both were replaced by before_action and skip_before_action.</p><p>I did mention before when I was getting the Rails 3.2 ready to be migrated, I moved controllers specs to become integration specs. Within those specs, the controller logic is executed when a call like this happens:</p><pre>post &quot;/share/1&quot;, nil, { &quot;X-Extra-Header&quot; =&gt; &quot;123&quot; }</pre><p>The first parameter is the Rails path to hit, next request parameters and finally a hash of headers to send. This API was updated to use keyword arguments, it means that instead of passing parameters by position, now we need to name parameters as follow:</p><pre>post &quot;/share/1&quot;, headers: { &quot;X-Extra-Header&quot; =&gt; &quot;123&quot; }</pre><p>Given that we are not sending parameters it gets omitted in our call, but if you need to pass parameters to your call just call it with:</p><pre>post &quot;/share/1&quot;, headers: { &quot;X-Extra-Header&quot; =&gt; &quot;123&quot; }, params: { resource_id: 2 }</pre><p>After these changes, my test suite was green and have no more warnings.</p><p>The application was deployed to an staging environment to Heroku for additional testing but it was failing when calling very specific end points. The error was something like NameError: uninitialized constant XXX where XXXwas the name of the constant.</p><p>It turns out that the class file was present in Rails lib directory and it was loaded correctly in development and test environments thanks to the setting config.autoload_paths += %W(#{config.root}/lib) in our application.rb file, but it was not working in production.</p><p>Because <a href="https://github.com/rails/rails/commit/a71350cae0082193ad8c66d65ab62e8bb0b7853b">autoloading is disabled in production</a> with Rails 5, using autoload_paths will not load needed classes from specified paths. The solution to this, is to ask Rails to eager load classes, this can be done by replacing config.autoload_paths += %W(#{config.root}/lib) with config.eager_load_paths += %W(#{config.root}/lib).</p><p>After this final change, the migration was complete.</p><h3>Additional bonus, replace RSpec with Minitest</h3><p>Migration of the Rails project happened very smoothly, having the test suite covering important areas of the application helped a lot.</p><p>After finishing the upgrade and given that I’m a Minitest fan, I wanted to find out how much effort required to migrate from RSpec to Minitest. It was very simple to migrate, I was able to automate something between 90% and 95% the migration of tests and only a few of them required to review the test and manually migrate it.</p><p>First I renamed the spec directory to test, next in Gemfile I removed RSpec dependencies and added minitest-rails. After running bundle update I ran rails g minitest:install to generate a test_helper.rb file.</p><p>I copied from spec_helper.rb file what did make sense to have in the new test_helper.rb, this will depend on your project.</p><p>Next, I used command rename to rename all files from *_spec.rb to *_test.rb. rename can be installed in MacOS using Homebrew.</p><pre>find . -name &#39;*_spec.rb&#39; -exec rename &#39;s|_spec|_test|&#39; {} \;</pre><p>Now with the following commands, I automated most of the syntax changes between RSpec and Minitest.</p><pre>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/spec_helper/test_helper/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/context/describe/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/stub(/stubs(/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/double/stub/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/should_receive/expects/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/and_return/returns/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/expect(//g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/).to be ==/.must_equal/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/).to eq/.must_equal/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/).to be_empty/.must_be_empty/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/).to_not be_empty/.wont_be_empty/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/).to be_kind_of/.must_be_kind_of/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie ’s/(response).to have_http_status/.must_respond_with/g’ {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/).to redirect_to/.must_redirect_to/g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/RSpec.//g&#39; {} \;<br>find . -name &#39;*_test.rb&#39; -exec sed -ie &#39;s/).to match/.must_match/g&#39; {} \;</pre><p>After this was done, it was a matter of running the test suite and fix any failing test. All failures were related to changes in syntax and as I said before it was a very small number of tests, most of them just passed without a problem.</p><p>The only gotcha is that integration tests in Minitest with the spec syntax need to be named in a way that it ends with Integration Test, like Share a resource Integration Test.</p><p>This post was my initial reference for this migration <a href="http://theartandscienceofruby.com/2015/09/11/switching-from-rspec-to-minitest/">Switching from RSpec to Minitest</a>.</p><h3>Conclusions</h3><p>Migration of this project for our client wasn’t so bad, it took me about a week to complete it. The application wasn’t too big and I just did the minimal changes to make it work in Rails 5. It still has a lot of room for cleaning and refactoring but for now, our client is satisfied to be running with the latest stack of Ruby and Rails.</p><p>If your team is looking for help to migrate a Rails application from any older version to a newer one, please contact us at <a href="/service/mailto://info@michelada.io">info@michelada.io</a> we will be more than happy to help, no matter if is a small or a big project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3856d63c506" width="1" height="1" alt=""><hr><p><a href="https://medium.com/michelada-io/upgrading-a-ruby-on-rails-application-a3856d63c506">Upgrading a Ruby on Rails application</a> was originally published in <a href="https://medium.com/michelada-io">michelada.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Method transplanting in Ruby]]></title>
            <link>https://medium.com/michelada-io/method-transplanting-in-ruby-648c9f72bc64?source=rss----6aae07d6a13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/648c9f72bc64</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mario Alberto Chávez]]></dc:creator>
            <pubDate>Wed, 04 Oct 2017 16:39:12 GMT</pubDate>
            <atom:updated>2017-10-04T17:05:01.243Z</atom:updated>
            <content:encoded><![CDATA[<p>I had the chance to watch Akira Matsuda’s live streaming presentation from RubyConf 2015; Ruby 2 Methodology. presentation name, the talk is about what you can do with methods in Ruby.</p><p>Recorded video is still not available, although his slides are on Speaker Deck <a href="http://blog.michelada.io/method-transplanting-in-ruby#">https://speakerdeck.com/a_matsuda/ruby-2-methodology</a>.</p><p>Matsuda’s presentation is a nice overview on how to work with methods in Ruby. It is not a talk about new features, it’s more of a talk about his findings on how to use methods effectively in Ruby.</p><p>From all the cases presented, there was one feature that I found particularly interesting: Method Transplanting.</p><h3>Method transplanting</h3><p>Method transplanting is a way for you to unbound a method from a module and bound it back into a class. Here is the example Matsuda used in his slides:</p><pre>module Greeter<br>  def hello<br>    p &#39;hello&#39;<br>  end<br>end</pre><pre>class Cat<br>  define_method :hello, Greeter.instance_method(:hello)<br>end</pre><pre>Cat.new.hello<br>#=&gt; &quot;hello&quot;</pre><p>Method <em>:hello</em> was successfully transplanted from module <em>Greeter</em> into class <em>Cat</em>.</p><p>You will probably say, <em>“well, I have being doing this for a while including modules into classes, how is this different?”</em>.</p><pre>module Greeter<br>  def hello<br>    p &#39;hello&#39;<br>  end<br>end</pre><pre>class Cat<br>  include Greeter<br>end</pre><pre>Cat.new.hello<br>#=&gt; &quot;hello&quot;</pre><p>You are right, kind of. By using include and method transplanting you can achieve almost the same result, however, let’s see how they are different.</p><p>For our example where the method was transplanted, if you ask the class to report its <em>public_instance_methods</em> ignoring ancestors you will get:</p><pre>Cat.public_instance_methods(false)<br>#=&gt; [:hello]<br>Cat.new.respond_to?(:hello)<br>#=&gt; true</pre><p>Looks like <em>:hello</em> truly belongs to <em>Cat</em>. You unbounded <em>:hello </em>method from the <em>Greeter</em> module and then bounded it back to the <em>Cat</em> class.</p><p>Now, by doing the same for the version where you include the module you get:</p><pre>Cat.public_instance_methods(false)<br>#=&gt; []<br>Cat.new.respond_to?(:hello)<br>#=&gt; true</pre><p>The <em>:hello</em> method is not bound to the <em>Cat</em> class, it’s still bound to the <em>Greeter</em> module.</p><p>The most interesting point of this feature is the possibility to cherry pick which methods you want to transplant from any module to your class.</p><p>Most of the time, when you consider including a module in a class, there is a concern due to the possibility of polluting its interface. If you are on Ruby 2.0 or better, you can now opt to simply transplant what you need.</p><p>Let’s see another example.</p><pre>module Greeter<br>  def say_hi<br>    puts &quot;Hi!&quot;<br>  end</pre><pre>  def say_bye<br>    puts &quot;Bye!&quot;<br>  end<br>end</pre><pre>class Cat<br>  define_method :say_bye, Greeter.instance_method(:say_bye)<br>end</pre><pre>Cat.public_instance_methods(false)<br>#=&gt; [:say_bye]<br>Cat.new.say_bye<br>#=&gt; &quot;Bye!&quot;<br>Cat.new.respond_to?(:say_hi)<br>#=&gt; false</pre><p>In this example you are cherry picking only what you want to transplant to your class. By doing this you are keeping the class neat, avoiding any unnecessary method definitions from the Greeter module.</p><h3>Use module</h3><p>Let’s create a module which will define a class method named use that will allow us to transplant methods with this signature <em>use Greeter, only:[:say_bye]</em>.</p><pre>module Use<br>  def use(source, only: [])<br>    if !only.respond_to?(:to_ary)<br>      only = [only]<br>    end</pre><pre>    if only.empty?<br>      only = source.public_instance_methods(false)<br>    end</pre><pre>    only.each do |method|<br>      define_method method, source.instance_method(method)<br>    end<br>  end<br>end</pre><p>This is an example on how you could transplant methods with the <em>Use</em> module.</p><pre>class Cat<br>  extend Use<br>  use Greeter, only: [:say_bye]<br>end</pre><pre>Cat.public_instance_methods(false)<br>#=&gt; [:say_bye]<br>Cat.new.say_bye<br>#=&gt; &quot;Bye!&quot;<br>Cat.new.respond_to?(:say_hi)<br>#=&gt; false</pre><p>The syntax is simpler, the param only can accept an array with the symbol, or just a single symbol of methods that you want to transplant.</p><p>If the param only is not present, then all the instance methods of our module are transplanted into our class. However, this is something that you want to avoid and simply use the old plain include.</p><p>Ruby 2.2 or newer not only supports method transplanting from a module but also from a class.</p><h3>Conclusions</h3><p>Method transplanting is an elegant solution to keeping classes clean. This solution will work perfectly when a transplanted method has no dependencies on other methods from the original module considering unbound/bound do not track them.</p><p>I have been writing Ruby programs for several years now, but it still amazes me that there are so many features within the language that are not so popular or common.</p><p>Transplanting methods feel useful, especially in Rails development, where almost everything is breaking down to modules.</p><p>Also, you have to admit that saying “I’m transplanting these methods” instead of “I’m including these methods” sounds nicer.</p><p><em>Originally published at </em><a href="http://blog.michelada.io/"><em>blog.michelada.io</em></a><em>. Check out Michelada.io at </em><a href="http://michelada.io/"><em>michelada.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=648c9f72bc64" width="1" height="1" alt=""><hr><p><a href="https://medium.com/michelada-io/method-transplanting-in-ruby-648c9f72bc64">Method transplanting in Ruby</a> was originally published in <a href="https://medium.com/michelada-io">michelada.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in Rails 5?]]></title>
            <link>https://medium.com/michelada-io/what-s-new-in-rails-5-19959c7b05d1?source=rss----6aae07d6a13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/19959c7b05d1</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Mario Alberto Chávez]]></dc:creator>
            <pubDate>Wed, 04 Oct 2017 16:37:43 GMT</pubDate>
            <atom:updated>2017-10-04T17:04:40.234Z</atom:updated>
            <content:encoded><![CDATA[<p>Rails 5 was announced on RailsConf past April. <a href="https://twitter.com/dhh">David Heinemeier Hansson</a> highlighted a few of the features that we can expect with the new release of Ruby on Rails.</p><p>He also talked about his vision on how building monolithic Ruby on Rails application is not that bad. You can agree or disagree with David’s opinions, but the truth is that modern Web Applications are more than just HTML and CSS and this is clear in the Ruby on Rails world, proof of this is the inclusion of Rails API and ActionCable.</p><p>The web has changed and, with it, Ruby on Rails also needs to change. So let us take a quick look at what is changing for the new version, Rails 5.</p><h3>Support for Ruby 2.2.2 or newer</h3><p>Rails 5 is a new major version of Ruby On Rails, this implicates that the Rails API and requirements can change to deprecate, add new, and/or improve existing APIs, but also to take advantage of important changes in the Ruby language as well.</p><p>The later is the most important reason on why Rails 5 will <a href="https://github.com/rails/rails/pull/19753">only work</a> with Ruby 2.2.2 or better.</p><p>In Ruby On Rails applications, we usually pass symbols all over the place, doing this open the possibility of <a href="http://brakemanscanner.org/docs/warning_types/denial_of_service/">DOS attacks</a> when our memory is consumed by symbols that never get garbage collected.</p><p>Ruby 2.2.0 introduced <a href="https://www.ruby-lang.org/en/news/2014/12/25/ruby-2-2-0-released/">changes</a> in its garbage collector to be able to collect symbols.</p><p>Another reason for Rails 5 to support Ruby 2.2.2 is to take advantage of new <a href="http://www.atdot.net/~ko1/activities/2014_rubyconf_pub.pdf">Incremental GC</a> which will help to reduce memory consumption by our Rails applications.</p><p>Rails 5 also started to leak Ruby 2.0 syntax into its source. <a href="https://github.com/rails/rails/pull/18872">Keyword</a> <a href="https://github.com/rails/rails/pull/18323">Arguments</a> and <a href="https://github.com/rails/rails/pull/19752">Module#prepend</a> are examples of the adoption of newer Ruby.</p><h3>API Deprecation and Cleanup</h3><p>Going through Rails <a href="https://github.com/rails/rails/commits/master">commits</a>, we will find changes related to removing code that was marked as deprecated in previous versions of Rails.</p><p>Notable removed APIs are:</p><h4>ActionMailer</h4><ul><li><em>#deliver</em> and <em>#deliver!</em> methods have been removed</li><li><em>*_path</em> helper in email views</li></ul><h4>ActiveRecord</h4><ul><li>Support for <em>protected_attributes</em> gem</li><li>Support for <em>activerecord-deprecated_finders</em> gem</li></ul><h4>ActionPack assertions</h4><ul><li><em>assert_template</em> and <em>assigns()</em> assertions are deprecated and moved into its own gem <a href="https://rubygems.org/gems/rails-controller-testing">rails-controller-testing</a>.</li></ul><p>Clean up in Rails 5 also includes dead code and unnecessary tests. Also, mocha is being removed from Rails tests in favor of plain Minitest stubbing.</p><h3>Performance improvements</h3><p>With Ruby 2.2.2, Rails 5 should get an improvement in performance, less memory usage, and less time spent in GC. This alone should help alone to bring this performance boost, but it’s not the only reason on why Rails 5 should perform better.</p><p>Seems that core team is determined to have a better/faster framework. Reducing object allocations, freezing immutable strings (BTW there is a discussion about having <a href="https://bugs.ruby-lang.org/issues/11473">immutable strings</a> by default in Ruby 3), removing unnecessary dependencies, and optimizing common operations have all helped to make Rails 5 faster.</p><p>The following are examples of commits focused on performance, it is worth to check them out, study, and understand the changes that have helped to reduce object allocations or code optimization because some of the lessons that can be learned in those commits can be applied to our own apps.</p><ul><li><a href="https://github.com/rails/rails/pull/21057">Beyond Ludicrous Speed</a></li><li><a href="https://github.com/rails/rails/pull/18643">Speed up ActionController::Renderer normalize_keys by ~28%</a></li><li><a href="https://github.com/rails/rails/pull/21411">10X speed improvements for AS::Dependencies.loadable_constants_for_path</a></li><li><a href="https://github.com/rails/rails/pull/21155">Speed up code and avoid unnecessary MatchData objects</a></li><li><a href="https://github.com/rails/rails/pull/20946">Freeze string literals when not mutated.</a></li></ul><h3>So, what is new in Rails 5?</h3><p>So far we have seen how Rails 5 will be faster with the introduced changes but we haven’t seen (yet) what is new in terms of functionality or new API.</p><h4>#or method in ActiveRecord::Relation</h4><p>Finally ActiveRecord::Relation is getting <em>#or</em> method, this will allow us to write queries with ActiveRecord DSL as follows:</p><pre>Book.where(&#39;status = 1&#39;).or(Book.where(&#39;status = 3&#39;))<br>\# =&gt; SELECT * FROM books WHERE (status = 1) OR (status = 3)</pre><p><em>#or</em> method accepts a second relation as a parameter that is combined with an or.</p><h3>#belongs_to is required by default</h3><p>From now on every Rails application will have a new configuration option <em>config.active_record.belongs_to_required_by_default = true</em>, it will trigger a validation error when trying to save a model where belongs_to associations are not present.</p><p><em>config.active_record.belongs_to_required_by_default</em> can be changed to false and with this keep old Rails behavior or we can disable this validation on each <em>belongs_to</em> definition, just passing an additional option <em>optional: true</em> as follows:</p><pre>class Book &lt; ActiveRecord::Base<br>   belongs_to :author, optional: true<br>end</pre><h4>ActiveRecord’s attribute API</h4><p>This <a href="http://edgeapi.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html">new API</a> adds functionality on top of ActiveRecord models, it made possible to override an attribute type to be a different type.</p><p>Consider the case where we have a field in the database defined as decimal but in our app we only care for the integer part of the number. We can in our app just ignore the decimal part and format our number everywhere we need to use it to only display the integer part.</p><p>With attribute API we can do this in an easy way:</p><pre>class Book &lt; ActiveRecord::Base<br>end</pre><pre>book.quantity # =&gt; 12.0</pre><pre>class Book &lt; ActiveRecord::Base<br>  attribute :quantity, :integer<br>end</pre><pre>book.quantity # =&gt; 12</pre><p>Here we are overriding the automatically generated attribute from the database schema to be cast in our model as an integer instead the original decimal. For every interaction of our model with the database, the attribute will be treated as a decimal as it should be.</p><p>We can even define our own custom types just by creating a class derived from <em>ActiveRecord::Type::Value</em> and <a href="http://edgeapi.rubyonrails.org/classes/ActiveRecord/Type/Value.html">implementing its contract</a> to <em>#cast</em>, <em>#serialize</em>, and <em>#deserialize</em> values.</p><p>Custom attributes will honor <em>ActiveModel::Dirty</em> to track changes in our models. Also, these new attributes can be virtual, so there is no need to be backed by a table column.</p><h3>has_secure_token landed in ActiveRecord</h3><p>An ActiveRecord model now can have <a href="https://github.com/rails/rails/pull/18217">token attributes</a> in an easy way. Common scenarios for token attributes are for cases when we need to create an invitation token or a password reset token for example.</p><p>Here is an example on how this works:</p><pre>class Invite &lt; ActiveRecord::Base<br>   has_secure_token :invitation_code<br>end</pre><pre>invite = Invite.new<br>invite.save<br>invite.invitation_code # =&gt; 44539a6a59835a4ee9d7b112<br>invite.regenerate_invitation_code # =&gt; true</pre><p>SecureRandom is being used to generate a 24-character token.</p><p>We can use the model generator to create needed migration for a token attribute, it requires from us to pass attribute type as <em>token</em>.</p><pre>$ rails g invite invitation_code:token</pre><p>Within the migration, a unique index will be created for our token column.</p><h3>MySQL ActiveRecord adapter gets JSON support</h3><p>If you happen to run your Rails application on top of MySQL 5.7.8 then your database have a new native JSON data type.</p><p>From Rails 5 you should be able to <a href="https://github.com/rails/rails/pull/21110">use this new data type</a> within yourActiveRecord models.</p><h3>Render a template outside controllers</h3><p>Rails 5 allows you to render templates or inline code outside controllers. This feature is important and useful for ActiveJob and the new ActionCable (we will discuss this one later).</p><p><em>ActionController::Renderer</em> is what makes this happen and it’s available in our ApplicationController class.</p><p>Let’s dig into few examples on how this works.</p><pre># render inline code<br>ApplicationController.render inline: &#39;&lt;%= &quot;Hello Rails&quot; %&gt;&#39; # =&gt; &quot;Hello Rails&quot;</pre><pre># render a template<br>ApplicationController.render &#39;sample/index&#39; # =&gt; Rendered sample/index.html.erb within layouts/application (0.0ms)</pre><pre># render an action<br>SampleController.render :index # =&gt; Rendered sample/index.html.erb within layouts/application (0.0ms)</pre><pre># render a file<br>ApplicationController.render file: ::Rails.root.join(&#39;app&#39;, &#39;views&#39;, &#39;sample&#39;, &#39;index.html.erb&#39;) # =&gt;   Rendered sample/index.html.erb within layouts/application (0.8ms)</pre><p>This is really nice but what if we need to pass assigns or locals to our template?</p><pre># Pass assigns<br>ApplicationController.render assigns: { rails: &#39;Rails&#39; }, inline: &#39;&lt;%= &quot;Hello #{@rails}&quot; %&gt;&#39; # =&gt; &quot;Hello Rails&quot;</pre><pre># Pass locals<br>ApplicationController.render locals: { hello: &#39;Hello&#39; }, assigns: { rails: &#39;Rails&#39; }, inline: &#39;&lt;%= &quot;#{hello} #{@rails}&quot; %&gt;&#39; # =&gt; &quot;Hello Rails&quot;</pre><p>Now if we have to use route helper’s functions like <em>root_url</em> or any other helper that needs access to the environment we can do it, but what <em>ActionController::Renderer</em> will receive is not a real environment. Take in account that we might use this functionality outside HTTP request.</p><pre>ApplicationController.render inline: &#39;&lt;%= root_url %&gt;&#39; # =&gt; &quot;http://example.org/&quot;</pre><pre># Inspect ActionController::Renderer environment<br>ApplicationController.renderer.defaults # =&gt; {:http_host=&gt;&quot;example.org&quot;, :https=&gt;false, :method=&gt;&quot;get&quot;, :script_name=&gt;&quot;&quot;, &quot;rack.input&quot;=&gt;&quot;&quot;}</pre><pre># To modify this environment we have to explicitly create a renderer<br>renderer = ApplicationController.renderer.new(<br>    http_host: &#39;michelada.io&#39;<br>  ) # =&gt; #&lt;#&lt;Class:0x007fdf9985a338&gt;:0x007fdf947981c0 @env={&quot;HTTP_HOST&quot;=&gt;&quot;michelada.io&quot;, &quot;HTTPS&quot;=&gt;&quot;off&quot;, &quot;SCRIPT_NAME&quot;=&gt;&quot;&quot;, &quot;rack.input&quot;=&gt;&quot;&quot;, &quot;REQUEST_METHOD&quot;=&gt;&quot;GET&quot;, &quot;action_dispatch.routes&quot;=&gt;#&lt;ActionDispatch::Routing::RouteSet:0x007fdf93d29450&gt;}&gt;<br>  <br>renderer.render inline: &#39;&lt;%= root_url %&gt;&#39; # =&gt; &quot;http://michelada.io/&quot;</pre><h3>Better Minitest test runner</h3><p>I have been using Minitest with Rails since test_unit was removed from Rails. I really like the simplicity of Minitest and I never missed anything from RSpec, pretty much Minitest fulfilled all my needs for testing.</p><p>The only issue that I had in the past with Minitest in Rails, was that the runner seems so basic. This is not the case anymore, its integration with Rails has been <a href="https://github.com/rails/rails/pull/19571">improved</a>.</p><p>Now when you execute <em>bin/rails test -h</em> you get the following help screen with a few nice things:</p><ul><li>Run tests filtered by a pattern</li><li>Execute a single test by specifying file and line number</li><li>Execute tests in specific files/directories</li></ul><pre>$ bin/rails test -h<br>minitest options:<br>    -h, --help                       Display this help.<br>    -s, --seed SEED                  Sets random seed. Also via env. Eg: SEED=n rake<br>    -v, --verbose                    Verbose. Show progress processing files.<br>    -n, --name PATTERN               Filter run on /regexp/ or string.</pre><pre>Known extensions: pride, rails<br>    -p, --pride                      Pride. Show your testing pride!</pre><pre>Usage: bin/rails test [options] [files or directories]<br>You can run a single test by appending a line number to a filename:</pre><pre>    bin/rails test test/models/user_test.rb:27</pre><pre>You can run multiple files and directories at the same time:</pre><pre>    bin/rails test test/controllers test/integration/login_test.rb</pre><pre>Rails options:<br>    -e, --environment ENV            Run tests in the ENV environment<br>    -b, --backtrace                  Show the complete backtrace</pre><p>Finally, the reporter gives you a command to rerun failed tests</p><pre>$ bin/rails test<br>Run options: --seed 41988</pre><pre># Running:</pre><pre>F</pre><pre>Finished in 0.028552s, 35.0239 runs/s, 35.0239 assertions/s.</pre><pre>  1) Failure:<br>UserTest#test_the_truth [/Users/marioch/Development/proyectos/edge/cinco/test/models/user_test.rb:5]:<br>Failed assertion, no message given.</pre><pre>1 runs, 1 assertions, 1 failures, 0 errors, 0 skips</pre><pre>Failed tests:</pre><pre>bin/rails test test/models/user_test.rb:4</pre><h3>Turbolinks 3</h3><p>Turbolinks has been part of Rails since version 4, probably one of the features that people hate it or love; there is no middle ground here.</p><p>With Rails 5 we will be receiving a <a href="https://github.com/rails/turbolinks">new version</a> that, with the help of HTML5 custom data attributes, we will expect better speed and rendering in our Rails applications.</p><p>The most significative change in this new version is the Partial Replacement feature. From the client side, we will be able to tell Turbolinks what content do we need to change/replace and what we don’t.</p><p>Turbolinks will look for HTML5 custom attributes <em>data-turbolinks-permanent</em> and <em>data-turbolinks-temporary</em> to decide the replacement strategy in our DOM.</p><p>To trigger a replacement in the client side we could use <em>Turbolinks.visit</em> or <em>Turbolinks.replace</em> to update our DOM. The difference between visit and replace is that the first one will issue a <em>GET</em> to the server to obtain the HTML that must be used to replace our DOM while replace expects from us the HTML that should be used for its operation.</p><p>With both functions, we can pass a hash with an <em>id</em> or an array of <em>id</em> of HTML elements to change or keep.</p><ul><li><em>Turbolinks.visit(url, { change: [‘entries’] })</em>: Will replace any DOM element with custom attribute <em>data-turbolinks-temporary</em> and any element with its <em>id</em> listed in change.</li><li><em>Turbolinks.visit(url)</em>: Will keep only DOM elements with custom attribute <em>data-turbolinks-permanent</em> and replace everything.</li><li><em>Turbolinks.visit(url, { keep: [‘flash’] })</em>: Will keep only DOM elements with custom attribute <em>data-turbolinks-permanent</em> and any element with its <em>id</em> listed in keep, everything else will be replaced.</li><li><em>Turbolinks.visit(url, { flush: true })</em>: Will replace everything.</li></ul><p>We can trigger the same functionality from the server-side with <em>redirect_to</em> and <em>render</em>, both can receive <em>change</em>, <em>keep</em> and <em>flush</em> as options but <em>redirect_to</em> can also receive <em>turbolinks</em> with <em>true</em> or <em>false</em> to force a redirect with or without Turbolinks.</p><p>Whether you like Turbolinks or not, this might be a good time to try out and find out if it could be a good fit somewhere in your application.</p><h3>Rails API</h3><p>Rails API was the opinionated way to build APIs with Ruby on Rails. Rails API was a separate gem with its own generator to build the skeleton of API applications.</p><p>Its goal was to help to create fast Rails API application by removing unnecessary middleware while providing sensitive defaults for these kinds of applications.</p><p>Starting with Rails 5, Rails API is <a href="https://github.com/rails/rails/pull/19832">integrated into the framework</a>, there is no need to include additional gems. To create a new API only Rails app we just pass the <em>--api</em> option to rails command.</p><pre>$ rails new michelada-api --api</pre><p>The new application will include <em>ActiveModelSerializers</em> and will remove JQuery and Turbolinks gems from our Gemfile. Also, <em>config/application.rb</em> and <em>aplication_controller.rb</em> files to have <em>config.api_only = true</em> option and to not check for <em>CSRF protection</em>, also it will be inherited from <em>ActionController::API</em>.</p><pre># application.rb file<br>module MicheladaApi<br>  class Application &lt; Rails::Application<br>     config.api_only = true<br>  end<br>end</pre><pre># application_controller.rb file<br>class ApplicationController &lt; ActionController::API<br>end</pre><p>If you want to learn more about creating Rails API application, here is a starter post from WyeWorks: <a href="http://wyeworks.com/blog/2015/6/30/how-to-build-a-rails-5-api-only-and-ember-application/">“HOW TO BUILD A RAILS 5 API ONLY AND EMBER APPLICATION”</a></p><h3>ActionCable</h3><p><a href="https://github.com/rails/actioncable">ActionCable</a> is the new thing in Rails 5, it is a framework for real-time communication over web sockets.</p><p>An ActionCable server will expose one or more channels into where a consumer will be able to subscribe via web socket connection, each channel broadcast messages to all subscribers in real-time.</p><p>Current ActionCable dependencies include the need of <a href="http://redis.io/">Redis</a> and its feature <a href="http://redis.io/topics/pubsub">PubSub</a>. It also requires on the Ruby side <a href="https://github.com/faye/faye-websocket-ruby">faye-websocket</a> and <a href="https://github.com/celluloid/celluloid">celluloid</a> although these may change in the future.</p><p>An application with ActionCable support requires of 3 basic components:</p><ul><li>Connection: Is a class derived from <em>ActionCable::Connection::Base</em>, this is where authorization and connection establishments happen.</li><li>Channel: This is what we will expose via web sockets and it is derived from <em>ActionCable::Channel::Base</em></li><li>Client: Is a javascript library to become an ActionCable client.</li></ul><p>ActionCable will require from us to start an additional server to respond to web sockets connections.</p><p>If you want to explore ActionCable, the Rails team has put together a Github repository with a <a href="https://github.com/rails/actioncable-examples">sample application</a>.</p><h2>Conclusions</h2><p>This is not the definitive list of changes or new features in Rails 5 but is just a quick glimpse on what can we expect on the new version.</p><p>There is no definitive date for when this might happen, but it still might happen this year. There is still <a href="https://github.com/rails/rails/pulls?page=2&amp;q=is%3Aopen+is%3Apr+milestone%3A5.0.0">68 open pull request</a> for Rails 5 milestone in Github.</p><p>Without a doubt, it is time to prepare our applications for the upgrade; just because of the performance improvements are worth it. If you are on Rails 4.x, the upgrade is almost painless.</p><p><em>Originally published at </em><a href="http://blog.michelada.io/"><em>blog.michelada.io</em></a><em>. Check out Michelada.io at </em><a href="http://michelada.io/"><em>michelada.io</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19959c7b05d1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/michelada-io/what-s-new-in-rails-5-19959c7b05d1">What’s new in Rails 5?</a> was originally published in <a href="https://medium.com/michelada-io">michelada.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Welcome to our blog]]></title>
            <link>https://medium.com/michelada-io/welcome-to-our-blog-52a2f643d1e4?source=rss----6aae07d6a13a---4</link>
            <guid isPermaLink="false">https://medium.com/p/52a2f643d1e4</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[David Padilla]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 23:39:20 GMT</pubDate>
            <atom:updated>2022-10-04T16:48:02.214Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi. Thanks for reading this and welcome to our very first post… ever.</p><p>It’s our first post because we’re quite a new company. However, we’re not new to the business: we’ve all been producing software for a while now.</p><p>Michelada is (for now) a very small company. There’s only five of us working here right now. But, the five of us have been working together for more than four years building amazing products for companies like yours.</p><p>So, after a small hiatus where all of us parted ways and tried different things, we decided to come together and start our own company. And here we are.</p><p>We specialize in Ruby, Rails, Node, Objective-C and whatever is needed to turn your ideas into products. We can also add up to your current team if what you need is to increase your development power for a few weeks.</p><p>I just wanted to let you know that we are ready and available to help you. We can talk the details if you write to us at <a href="/service/mailto:info@michelada.io">info@michelada.io</a>.</p><p>Looking forward to doing business with you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52a2f643d1e4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/michelada-io/welcome-to-our-blog-52a2f643d1e4">Welcome to our blog</a> was originally published in <a href="https://medium.com/michelada-io">michelada.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>