<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Ruby Howto on developwith — developer tips</title>
    <link>https://developwith.com/tags/ruby-howto/</link>
    <description>Recent content in Ruby Howto on developwith — developer tips</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 14 May 2019 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://developwith.com/tags/ruby-howto/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Ruby</title>
      <link>https://developwith.com/how-do-i/ruby/</link>
      <pubDate>Tue, 14 May 2019 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/</guid>
      <description>&lt;p&gt;Practical answers for building with Ruby and Rails.&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I add character encoding to the Heroku buildpack?&lt;/strong&gt; — Get charlock_holmes working on Heroku with a custom buildpack. &lt;a href=&#34;add-character-encoding-to-heroku-buildpack/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I add image processing to the Heroku buildpack?&lt;/strong&gt; — Compile image libraries for Rails image manipulation on Heroku. &lt;a href=&#34;add-image-processing-heroku-buildpack/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I bulk insert records that don&amp;rsquo;t already exist?&lt;/strong&gt; — Upsert patterns with ActiveRecord and raw SQL. &lt;a href=&#34;bulk-insert-when-doesnt-exist/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I cancel a Recurly subscription programmatically?&lt;/strong&gt; — Use the Recurly Ruby SDK to cancel and manage subscriptions. &lt;a href=&#34;cancel_recurly_subscription_programmatically/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I create a custom tag with attributes in Jekyll?&lt;/strong&gt; — Parse and render custom Liquid tags with named parameters. &lt;a href=&#34;custom-tag-with-attributes-in-jekyll/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I eager load children in ActiveRecord?&lt;/strong&gt; — Use includes and preload to avoid N+1 queries. &lt;a href=&#34;eager-load-children-in-active-record/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I fix a handlebars.vm include error?&lt;/strong&gt; — Resolve gem version conflicts that cause runtime load errors. &lt;a href=&#34;fix-cant-include-error/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I fix the Psych YAML issue on RVM and macOS?&lt;/strong&gt; — Fix path2class errors when RVM and Homebrew Ruby conflict. &lt;a href=&#34;fix-psych-issue-on-rvm/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I flatten a hash into a string?&lt;/strong&gt; — Convert nested hashes into flat key-value strings. &lt;a href=&#34;flatten-hash-to-string/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I look up HTTP status codes in Rails?&lt;/strong&gt; — Symbol and numeric status code reference for Rails controllers. &lt;a href=&#34;http-status-codes/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I pass variables to a partial in Rails?&lt;/strong&gt; — Use locals to send data from parent templates to partials. &lt;a href=&#34;pass-variables-to-partial/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I recover from a load error?&lt;/strong&gt; — Auto-install missing gems when a LoadError is raised. &lt;a href=&#34;recover-a-load-error/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I use RSpec tips and tricks?&lt;/strong&gt; — Run individual tests, bisect failures, and add detail to output. &lt;a href=&#34;rspec-tips-and-tricks/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I run SQL in Rails migrations?&lt;/strong&gt; — Execute raw SQL alongside schema changes in migration files. &lt;a href=&#34;run-sql-in-migrations/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I set up a custom Ruby buildpack?&lt;/strong&gt; — Add compilation steps to the standard Heroku Ruby buildpack. &lt;a href=&#34;setup-custom-ruby-buildpack/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I get the size of an ActiveRecord collection?&lt;/strong&gt; — Count, length, and size — when to use each method. &lt;a href=&#34;size-of-active-record-collection/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I convert a string to a class reference?&lt;/strong&gt; — Use constantize and safe_constantize for dynamic class lookup. &lt;a href=&#34;turn-a-string-into-class/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I get unique records from a list?&lt;/strong&gt; — Deduplicate ActiveRecord result sets while preserving objects. &lt;a href=&#34;uniq-list-with-records/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I URL-encode a string in Ruby?&lt;/strong&gt; — Encode query parameters and form data using standard library methods. &lt;a href=&#34;url-encoded-string/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;li&gt;&lt;strong&gt;How do I use modules for testing?&lt;/strong&gt; — Mock behavior by including test modules instead of full mocking frameworks. &lt;a href=&#34;use-modules-for-testing/&#34;&gt;→ Read more&lt;/a&gt;&lt;/li&gt;&#xA;&lt;/ul&gt;</description>
    </item>
    <item>
      <title>Run SQL updates in Rails migration</title>
      <link>https://developwith.com/how-do-i/ruby/run-sql-in-migrations/</link>
      <pubDate>Tue, 14 May 2019 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/run-sql-in-migrations/</guid>
      <description>&lt;p&gt;The proper way to run Ruby migrations is with the &lt;code&gt;change&lt;/code&gt; definition. This allows rollbacks to remove any column or change that is run inside that block and reduces the need to have an &lt;code&gt;up&lt;/code&gt; and &lt;code&gt;down&lt;/code&gt; method to reverse the changes. But, sometimes you need to run some updates on a new table or column that is added to the database. In order, to do this you have to only run that sql on the &lt;code&gt;up&lt;/code&gt; state when the column exists.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Pass a variable to a partial in Rails</title>
      <link>https://developwith.com/how-do-i/ruby/pass-variables-to-partial/</link>
      <pubDate>Mon, 22 Apr 2019 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/pass-variables-to-partial/</guid>
      <description>&lt;p&gt;Rails partials are reusable view templates, but sometimes you need to pass data into them or handle optional variables. Here&amp;rsquo;s how to do it cleanly.&lt;/p&gt;&#xA;&lt;h2 id=&#34;passing-variables-to-a-partial&#34;&gt;Passing Variables to a Partial&lt;/h2&gt;&#xA;&lt;p&gt;Use the &lt;code&gt;locals&lt;/code&gt; option (or the shorthand hash syntax) to pass variables into a partial:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-erb&#34; data-lang=&#34;erb&#34;&gt;&amp;lt;%= render &amp;#34;shared/header&amp;#34;, headline: &amp;#34;Welcome&amp;#34;, person: person %&amp;gt;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;Inside &lt;code&gt;_header.html.erb&lt;/code&gt;, those locals are available as regular variables:&lt;/p&gt;&#xA;&lt;pre tabindex=&#34;0&#34;&gt;&lt;code class=&#34;language-erb&#34; data-lang=&#34;erb&#34;&gt;&amp;lt;h1&amp;gt;&amp;lt;%= headline %&amp;gt;&amp;lt;/h1&amp;gt;&#xA;&amp;lt;p&amp;gt;First name: &amp;lt;%= person.first_name %&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;h2 id=&#34;checking-for-optional-variables&#34;&gt;Checking for Optional Variables&lt;/h2&gt;&#xA;&lt;p&gt;If a partial might or might not receive a variable, use &lt;code&gt;local_assigns&lt;/code&gt; to check:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Http status Codes in Rails</title>
      <link>https://developwith.com/how-do-i/ruby/http-status-codes/</link>
      <pubDate>Sun, 07 Apr 2019 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/http-status-codes/</guid>
      <description>&lt;p&gt;I can never find the info when I need it so I&amp;rsquo;m mirroring the http codes here for me and everyone that comes across it.&lt;/p&gt;&#xA;&lt;h2 id=&#34;1xx-codes&#34;&gt;1XX Codes&lt;/h2&gt;&#xA;&lt;p&gt;These are information codes used to provide some information to the calling party.&lt;/p&gt;&#xA;&lt;table&gt;&#xA;  &lt;thead&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;th&gt;Status Code&lt;/th&gt;&#xA;          &lt;th&gt;Status Message&lt;/th&gt;&#xA;          &lt;th&gt;Symbol&lt;/th&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/thead&gt;&#xA;  &lt;tbody&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;100&lt;/td&gt;&#xA;          &lt;td&gt;Continue&lt;/td&gt;&#xA;          &lt;td&gt;:continue&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;101&lt;/td&gt;&#xA;          &lt;td&gt;Switching Protocols&lt;/td&gt;&#xA;          &lt;td&gt;:switching_protocols&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;      &lt;tr&gt;&#xA;          &lt;td&gt;102&lt;/td&gt;&#xA;          &lt;td&gt;Processing&lt;/td&gt;&#xA;          &lt;td&gt;:processing&lt;/td&gt;&#xA;      &lt;/tr&gt;&#xA;  &lt;/tbody&gt;&#xA;&lt;/table&gt;&#xA;&lt;h2 id=&#34;2xx-codes&#34;&gt;2XX Codes&lt;/h2&gt;&#xA;&lt;p&gt;The 200 series codes are used to provide a success message to the calling party.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Add Character Encoding to Heroku buildpack</title>
      <link>https://developwith.com/how-do-i/ruby/add-character-encoding-to-heroku-buildpack/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/add-character-encoding-to-heroku-buildpack/</guid>
      <description>&lt;p&gt;In this tutorial, we&amp;rsquo;ll add the support for the &lt;code&gt;charlock_holmes&lt;/code&gt; library to a heroku build pack. The &lt;code&gt;icu4c&lt;/code&gt; is a native extension that is used for processing character encoding in ruby.&lt;/p&gt;&#xA;&lt;p class=&#34;tip&#34;&gt;&lt;strong&gt;Setup:&lt;/strong&gt; Take a look at [setting up a custom build pack](/how-do-i/ruby/setup-custom-ruby-buildpack.html) article.&lt;/p&gt;&#xA;&lt;p&gt;First, create an S3 bucket to store the binary library for use in your build pack. Let&amp;rsquo;s call it &lt;code&gt;my-heroku-binaries&lt;/code&gt;. In the &lt;code&gt;lib/language_pack/base.rb&lt;/code&gt;, add a variable for your binary bucket.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Add Image Processing to Heroku buildpack</title>
      <link>https://developwith.com/how-do-i/ruby/add-image-processing-heroku-buildpack/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/add-image-processing-heroku-buildpack/</guid>
      <description>&lt;p&gt;In this tutorial, we&amp;rsquo;ll add the &lt;code&gt;image_processing&lt;/code&gt; library to a heroku build pack. The &lt;code&gt;libgd&lt;/code&gt; is a native extension that is used for processing images in ruby.&lt;/p&gt;&#xA;&lt;p class=&#34;tip&#34;&gt;&lt;strong&gt;Setup:&lt;/strong&gt; Take a look at [setting up a custom build pack](/how-do-i/ruby/setup-custom-ruby-buildpack.html) article.&lt;/p&gt;&#xA;&lt;p&gt;First, create an S3 bucket to store the binary library for use in your build pack. Let&amp;rsquo;s call it &lt;code&gt;my-heroku-binaries&lt;/code&gt;. In the &lt;code&gt;lib/language_pack/base.rb&lt;/code&gt;, add a variable for your binary bucket.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nv&#34;&gt;MY_BINARY_URL&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;https://s3.amazonaws.com/my-heroku-binaries&amp;#39;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;Build the binary for &lt;code&gt;libgd2&lt;/code&gt; using &lt;a href=&#34;https://github.com/heroku/vulcan&#34;&gt;vulcan&lt;/a&gt;. See Ryan Daigle&amp;rsquo;s tutorial on &lt;a href=&#34;http://www.higherorderheroku.com/articles/using-vulcan-to-build-binary-dependencies-on-heroku/&#34;&gt;building with vulcan&lt;/a&gt;. Download the binary and put it in your bucket.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Cancel Recurly Subscription Programmatically</title>
      <link>https://developwith.com/how-do-i/ruby/bulk-insert-when-doesnt-exist/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/bulk-insert-when-doesnt-exist/</guid>
      <description>&lt;p&gt;When you need to cancel a &lt;a href=&#34;https://recurly.com/&#34;&gt;Recurly&lt;/a&gt; subscription in Ruby, the Recurly gem provides a few options depending on whether you want an immediate cancellation or one at the end of the billing period.&lt;/p&gt;&#xA;&lt;h2 id=&#34;bulk-insert-records-that-dont-already-exist&#34;&gt;Bulk Insert Records That Don&amp;rsquo;t Already Exist&lt;/h2&gt;&#xA;&lt;p&gt;A common pattern is inserting records in bulk, skipping any that already exist in the database. This avoids &lt;code&gt;N+1&lt;/code&gt; queries and is far more efficient than checking each record individually.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Cancel Recurly Subscription Programmatically</title>
      <link>https://developwith.com/how-do-i/ruby/cancel_recurly_subscription_programmatically/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/cancel_recurly_subscription_programmatically/</guid>
      <description>&lt;p&gt;Subscriptions can be cancelled via the &lt;a href=&#34;http://docs.recurly.com/api/subscriptions&#34;&gt;Recurly API&lt;/a&gt;. To setup the recurly ruby api, you&amp;rsquo;ll need to install the recurly sdk gem. To install run &lt;code&gt;gem install recurly&lt;/code&gt; or add &lt;code&gt;gem &#39;recurly&#39;&lt;/code&gt; to your &lt;code&gt;Gemfile&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;There are a couple types of ways to cancel the subscription and to issue or not issue a refund. Refunds are based on a subscription cancelled before a reoccurring period is completed. There is the option to allow the subscription to be cancelled on the next reoccurring period (&lt;code&gt;:none&lt;/code&gt;) vs in the middle of the period (&lt;code&gt;:partial&lt;/code&gt;). For instance, if a user cancels a monthly subscription of $10.00, you could have a policy that will only cancel the following month payment vs refunding the partial amount in the current month.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Convert a string to class</title>
      <link>https://developwith.com/how-do-i/ruby/turn-a-string-into-class/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/turn-a-string-into-class/</guid>
      <description>&lt;h1 id=&#34;how-to-convert-a-string-to-class-in-ruby&#34;&gt;How to convert a string to class in Ruby?&lt;/h1&gt;&#xA;&lt;p&gt;First off, a string in ruby has a variety of methods on it to change the format to another format fairly easily. The main conversion methods are from a &lt;code&gt;snake_case&lt;/code&gt; string to a &lt;code&gt;CamelCase&lt;/code&gt; string. Class names in ruby are actually represented as a constant in CamelCase form.&lt;/p&gt;&#xA;&lt;p&gt;Start with converting to CamelCase string:&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;my_class_string&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;my_class&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;camel_case_string&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;my_class_string&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;camelize&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&#xA;&lt;p&gt;Next we have to make sure it is a singular class name. For instance, say someone passes in a class as &lt;code&gt;records&lt;/code&gt; you&amp;rsquo;d want to convert it to &lt;code&gt;record&lt;/code&gt;. Luckily, that is fairly simple as illustrated below.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Custom Ruby buildpack</title>
      <link>https://developwith.com/how-do-i/ruby/setup-custom-ruby-buildpack/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/setup-custom-ruby-buildpack/</guid>
      <description>&lt;h2 id=&#34;setup-heroku-tools-on-your-computer&#34;&gt;Setup Heroku tools on your computer&lt;/h2&gt;&#xA;&lt;p&gt;Install the Heroku toolbelt: &lt;a href=&#34;https://toolbelt.heroku.com/&#34;&gt;https://toolbelt.heroku.com/&lt;/a&gt;. Set up a Heroku&#xA;account. Run &lt;code&gt;heroku login&lt;/code&gt; to authenticate your computer.&lt;/p&gt;&#xA;&lt;h2 id=&#34;setup-buildpack-repo&#34;&gt;Setup buildpack repo&lt;/h2&gt;&#xA;&lt;p&gt;Start by cloning the &lt;a href=&#34;https://github.com/heroku/heroku-buildpack-ruby&#34;&gt;official Ruby buildpack&lt;/a&gt;. The reasons for making your own build pack is to add additional libraries and binaries over the default dyno environment.&lt;/p&gt;&#xA;&lt;p&gt;For this example, we&amp;rsquo;ll add building native rake extensions during the compilation process, ie. &lt;code&gt;rake extensions:build&lt;/code&gt;. Your ruby app may have non-gem C dependencies that must be compiled before boot by running &lt;code&gt;rake extensions:build&lt;/code&gt;. So we will add that convention to Heroku deploys via the updates on the &lt;a href=&#34;https://github.com/heroku/heroku-buildpack-ruby&#34;&gt;official Ruby buildpack&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Custom tag with attributes in Jekyll</title>
      <link>https://developwith.com/how-do-i/ruby/custom-tag-with-attributes-in-jekyll/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/custom-tag-with-attributes-in-jekyll/</guid>
      <description>&lt;p&gt;To illustrate how to process attributes in a Jekyll tag, we&amp;rsquo;ll create a tag that will include a partial file from the includes directory. Jekyll uses Liquid as the template languages. So, in order to hook into the template framework, we&amp;rsquo;ll need to extend &lt;code&gt;Liquid::Tag&lt;/code&gt;. This is pretty straight forward as you just need to override the render method, as seen below.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;PartialIncludeTag&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;Liquid&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;Tag&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;render&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;context&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;       &lt;span class=&#34;s2&#34;&gt;&amp;#34;hello we got a tag!&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;And in order to use the tag within your pages you&amp;rsquo;ll need to register it with &lt;code&gt;Jekyll&lt;/code&gt; and call it in your pages.  To register see the example below.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix Issue with Psych Yaml gem on RVM and OSX</title>
      <link>https://developwith.com/how-do-i/ruby/fix-psych-issue-on-rvm/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/fix-psych-issue-on-rvm/</guid>
      <description>&lt;p&gt;Every now and then you may see a &lt;code&gt;path2class&lt;/code&gt; error when using &lt;code&gt;ruby 2.0&lt;/code&gt;, &lt;code&gt;rvm&lt;/code&gt; and &lt;code&gt;pysch&lt;/code&gt; gem. This issue is typically caused on your OS X machine. To fix the issue, when getting something like:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;.rvm/rubies/ruby-2.0.0-p353/lib/ruby/2.0.0/psych/syntax_error.rb:5:in &lt;span class=&#34;sb&#34;&gt;`&lt;/span&gt;&amp;lt;module:Psych&amp;gt;&lt;span class=&#34;err&#34;&gt;&amp;#39;&lt;/span&gt;: superclass mismatch &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; class SyntaxError &lt;span class=&#34;o&#34;&gt;(&lt;/span&gt;TypeError&lt;span class=&#34;o&#34;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;Do the following:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;rvm reinstall 2.0.0-p353 --disable-binary&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;If you get a message where you have to update your &lt;code&gt;XCode&lt;/code&gt; install, go ahead and do that. You may run into an &lt;code&gt;rvm&lt;/code&gt; build error (eg. &amp;ldquo;Error running &amp;lsquo;make -j8&amp;rsquo;&amp;hellip;&amp;rdquo;).&lt;/p&gt;</description>
    </item>
    <item>
      <title>Fix the handlebars.vm error</title>
      <link>https://developwith.com/how-do-i/ruby/fix-cant-include-error/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/fix-cant-include-error/</guid>
      <description>&lt;p&gt;Every now and then you might see an error in your rails application that says it can&amp;rsquo;t include something. For instance, if you are working with handlebars in your asset pipeline you may get a &lt;code&gt;Can&#39;t include handlebars.vm error&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;Most of the time this is caused by a mismatch in libraries by running &lt;code&gt;bundle update&lt;/code&gt; instead of &lt;code&gt;bundle install&lt;/code&gt; on a project. To get yourself back to the right version checkout the original &lt;code&gt;Gemfile.lock&lt;/code&gt; file. Using git you can run the following:&lt;/p&gt;</description>
    </item>
    <item>
      <title>Flatten a Hash into a String</title>
      <link>https://developwith.com/how-do-i/ruby/flatten-hash-to-string/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/flatten-hash-to-string/</guid>
      <description>&lt;h1 id=&#34;flatten-a-hash-into-a-string&#34;&gt;Flatten a Hash into a String&lt;/h1&gt;&#xA;&lt;p&gt;Join is a powerful method that can be used in a variety of ways. It helps to ease the pain of working with various collections including hashes.&lt;/p&gt;&#xA;&lt;p&gt;Here is a simple technique on how to join a hash into a url name value pair.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;param_string&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;params&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;map&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;k&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;#{&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;k&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;#{&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;v&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;join&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;&amp;amp;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p class=&#34;tip&#34;&gt;Take a look at [Url Encoded String](/how-do-i/ruby/url-encoded-string/) article for how to encode the values.&lt;/p&gt;&#xA;&lt;p&gt;For more details on the ways to do this check out the stack flow article &lt;a href=&#34;http://stackoverflow.com/questions/3047007/flattening-hash-into-string-in-ruby&#34;&gt;Flattening hash into string in ruby&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Recover a Load Error</title>
      <link>https://developwith.com/how-do-i/ruby/recover-a-load-error/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/recover-a-load-error/</guid>
      <description>&lt;p&gt;Although recovering a &lt;code&gt;LoadError&lt;/code&gt; is not a preferred approach in Ruby development, sometimes its needed when you are building one-off command line scripts. It simplifies the installation of gems as the user is running the script.&lt;/p&gt;&#xA;&lt;p&gt;Below is the approach, to run the &lt;code&gt;GemRunner&lt;/code&gt; directly:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;begin&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;nb&#34;&gt;require&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;sass&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;rescue&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;LoadError&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;nb&#34;&gt;require&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;rubygems/gem_runner&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;n&#34;&gt;gemrunner&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;Gem&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;GemRunner&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;new&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;n&#34;&gt;gemrunner&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;run&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;install&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;nokogiri&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;--bindir&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;#{&lt;/span&gt;&lt;span class=&#34;no&#34;&gt;File&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;expand_path&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;File&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dirname&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;bp&#34;&gt;__FILE__&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;}&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;/bins&amp;#34;&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt; &lt;span class=&#34;nb&#34;&gt;require&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;sass&amp;#39;&lt;/span&gt;      &#x9;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;Again, typically you would want to define all your libraries in a &lt;code&gt;Gemfile&lt;/code&gt; and use &lt;code&gt;bundle&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Rspec tips and tricks</title>
      <link>https://developwith.com/how-do-i/ruby/rspec-tips-and-tricks/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/rspec-tips-and-tricks/</guid>
      <description>&lt;h2 id=&#34;general-tips&#34;&gt;General Tips&lt;/h2&gt;&#xA;&lt;p&gt;The negative of &lt;code&gt;.to&lt;/code&gt; is &lt;code&gt;.not_to&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;##Passing in params to a controller method##&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;params&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;ss&#34;&gt;:id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;1445&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;:project_id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1144&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;:accesskey&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;MyString&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;format&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;:json&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;get&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;:show&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;params&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;h2 id=&#34;seeing-a-view-rendered&#34;&gt;Seeing a view rendered&lt;/h2&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;describe&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;MyController&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;n&#34;&gt;render_views&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;describe&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;GET index &amp;#34;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;   &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;n&#34;&gt;it&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;success&amp;#34;&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;do&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;get&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;show&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;expect&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;response&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;be_success&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;expect&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;response&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;status&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;eq&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;200&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;      &lt;span class=&#34;n&#34;&gt;expect&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;response&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;kp&#34;&gt;include&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Hello World&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;##Running tests##&lt;/p&gt;&#xA;&lt;h3 id=&#34;run-individual-rspec&#34;&gt;Run individual rspec&lt;/h3&gt;&#xA;&lt;p&gt;To run all tests on a single rspec file, run the following:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;bundle &lt;span class=&#34;nb&#34;&gt;exec&lt;/span&gt; rspec spec/controllers/my_controller_spec.rb&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;To run a single test within that rspec file, there are a couple options. You can pass in the line number using flag &lt;code&gt;-l&lt;/code&gt;, example &lt;code&gt;-l 12&lt;/code&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Unique list with records</title>
      <link>https://developwith.com/how-do-i/ruby/uniq-list-with-records/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/uniq-list-with-records/</guid>
      <description>&lt;p&gt;Most of you probably know about how to create a unique list of values with an array using the &lt;code&gt;array.uniq&lt;/code&gt; in ruby. But did you know that you can pass in a block to &lt;code&gt;uniq&lt;/code&gt;? This makes it extremely convenient for getting a unique set of objects based on a given field value.&lt;/p&gt;&#xA;&lt;p&gt;For instance, here is an example of a unique array with id as the qualifier.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;model_arr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;[]&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;model_arr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;Model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;new&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;model_arr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;Model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;new&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;model_arr&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;Model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;new&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;model_arr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;uniq&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;|&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;|&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;model&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;id&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;The returned value in the block is what the array logic will use to clean up the duplicate values. The resulting array in the above example will be a length of 2.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Url encode strings</title>
      <link>https://developwith.com/how-do-i/ruby/url-encoded-string/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/url-encoded-string/</guid>
      <description>&lt;p&gt;Url encoding is quite easy in ruby there are a couple of ways depending on your need. Here are a few techniques:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;require&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;open-uri&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;no&#34;&gt;URI&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encode&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;and&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;nb&#34;&gt;require&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;open-uri&amp;#39;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;no&#34;&gt;URI&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;encode_www_form_component&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;For more details on the &lt;code&gt;uri&lt;/code&gt; class see &lt;a href=&#34;http://www.ruby-doc.org/stdlib-1.9.3/libdoc/uri/rdoc/URI.html&#34;&gt;Ruby Docs URI&lt;/a&gt;.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Use modules for testing</title>
      <link>https://developwith.com/how-do-i/ruby/use-modules-for-testing/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://developwith.com/how-do-i/ruby/use-modules-for-testing/</guid>
      <description>&lt;p&gt;There are certain cases when you are unit testing that you need to isolate behavior of an object interaction. Modules can become an important role in testing for just this type of isolation. To understand how this works, you&amp;rsquo;ll have to know how ruby deals with the call stack of an object. The last definition of a method of an object wins.&lt;/p&gt;&#xA;&lt;p&gt;For instance, say you have a class:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;class&lt;/span&gt; &lt;span class=&#34;nc&#34;&gt;World&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;def&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;hello&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;s2&#34;&gt;&amp;#34;world&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;k&#34;&gt;end&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;world&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;no&#34;&gt;World&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;new&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;world&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;hello&lt;/span&gt; &#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# results: &amp;#34;world&amp;#34;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&#xA;&lt;p&gt;Now if you extend a module, you can override method definitions of the object.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
