 <p>What you want to do is sort an array, whose elements are hash, based on the hash's "code" value.</p> <pre><code>entries.sort { |a, b| a["code"] &lt;=&gt; b["code"] } </code></pre> <p>And also, I would suggest you do this in your controller instead of view.</p> <p>EDIT:</p> <p>Or you could do sort the tag first, then mapping them into an Array</p> <pre><code>Ci::Canonical::Language::Tag.sort_by do |a, b| a.code &lt;=&gt; b.code end.map do |tag| { "code" =&gt; tag.code, "description" =&gt; tag.description, "ordinal" =&gt; tag.value, } end </code></pre>