<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Octothought]]></title>
  <link href="http://octothought.com/atom.xml" rel="self"/>
  <link href="http://octothought.com/"/>
  <updated>2021-12-11T12:39:47-08:00</updated>
  <id>http://octothought.com/</id>
  <author>
    <name><![CDATA[Benjamin Turner]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Precompiling Assets for a Rails Engine on Heroku]]></title>
    <link href="http://octothought.com/precompiling-assets-for-a-rails-engine-on-heroku/"/>
    <updated>2014-01-24T09:59:00-08:00</updated>
    <id>http://octothought.com/precompiling-assets-for-a-rails-engine-on-heroku</id>
    <content type="html"><![CDATA[<p>I&rsquo;ve been working on a project which is a
<a href="http://edgeguides.rubyonrails.org/engines.html">Rails Engine</a> and recently
struggled through getting the engine&rsquo;s asserts working within an app on <a href="https://www.heroku.com">Heroku</a>.
Because of how Heroku sets up the environment for the asset precompiliation
step (or <em>doesn&rsquo;t</em> set up the environment, as it happens), they <a href="https://devcenter.heroku.com/articles/getting-started-with-rails3#setting-up-the-asset-pipeline">recommend disabling the <code>initialize_on_precompile</code> setting</a> (many apps are unable to complete their normal initialization without their Heroku environment config, which isn&rsquo;t available during Heroku&rsquo;s build process;
turning off initialization during precompilation avoids that).</p>

<!-- MORE -->




<figure class='code'><figcaption><span>In your Rails application's config/application.rb</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">config</span><span class="o">.</span><span class="n">assets</span><span class="o">.</span><span class="n">initialize_on_precompile</span> <span class="o">=</span> <span class="kp">false</span>
</span></code></pre></td></tr></table></div></figure>


<p>Once you do that, however, asset precompilation won&rsquo;t trigger your Rails engine&rsquo;s initialization, so even if you&rsquo;ve set up your engine&rsquo;s assets for precompilation as described in the
<a href="http://edgeguides.rubyonrails.org/engines.html#separate-assets-precompiling">Rails Engine Guide</a>, your assets won&rsquo;t actually get precompiled. Why? Because when <code>initialize_on_precompile</code> is disabled, only <code>:assets</code> initializers are run during precompliation.</p>

<p>The trick is to get Rails to run your engine&rsquo;s initializer during asset
precompilation even though it&rsquo;s not actually initializing your whole
application. The magic incantation for that is to pass a special <code>:group =&gt; :assets</code> or <code>:group =&gt; :all</code> option to your engine&rsquo;s initializer, and make
sure you configure your precompiled in that initializer.</p>

<figure class='code'><figcaption><span>In your Rails engine's lib/<engine name>/engine.rb</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">initializer</span> <span class="s2">&quot;RocketEngine asset precompile&quot;</span><span class="p">,</span> <span class="ss">:group</span> <span class="o">=&gt;</span> <span class="ss">:all</span> <span class="k">do</span> <span class="o">|</span><span class="n">app</span><span class="o">|</span>
</span><span class='line'>  <span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">assets</span><span class="o">.</span><span class="n">precompile</span> <span class="o">+=</span> <span class="sx">%w(</span>
</span><span class='line'><span class="sx">    rocket.css </span>
</span><span class='line'><span class="sx">    rocket.js</span>
</span><span class='line'><span class="sx">  )</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>Voil&agrave;!</p>

<p>I first got this working by specifying <code>:group =&gt; :assets</code>, but it turns out
that <code>:assets</code> is <a href="https://github.com/rails/rails/blob/81f14a5433cbba3e7a6088156d9c548bc5c252ea/actionpack/lib/sprockets/assets.rake#L91">only used during asset precompilation when
<code>initialize_on_precompile</code> is explicitly disabled</a>.
So if you want your engine&rsquo;s asset precompilation to work on other platforms
as well as Heroku you should use <code>:group =&gt; :all</code> (which is special-cased to
always run).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[CocoaConf PDX 2013]]></title>
    <link href="http://octothought.com/cocoaconf-pdx-2013/"/>
    <updated>2013-08-20T14:28:00-07:00</updated>
    <id>http://octothought.com/cocoaconf-pdx-2013</id>
    <content type="html"><![CDATA[<p>Although most of my work is on web applications and services, I also dabble in
Objective-C, iPhone, and Mac
development (someday I hope to ship some of it&hellip;). As luck would have
it, <a href="http://cocoaconf.com">CocoaConf</a> happened to have a stop in my
hometown, and it was at a hotel out near the airport, so I could just hop on
the MAX to get there. The early registration price was a pretty reasonable
number by conference standards, so I decided to check it out and see what
I could learn to help me get going on some of my own projects.</p>

<p>In short, it was a great conference&mdash;well worth the cost of admission and
the time spent. There were two days of really great talks (and a third day of
tutorial/workshop sessions that I didn&rsquo;t attend) put together by
developers who really want to share their knowledge.</p>

<!-- MORE -->


<p>I especially enjoyed the relatively small size of the conference, since it
really brought everyone together and felt like an actual community rather than
just a crowd. <a href="http://www.oscon.com/">OSCON</a> is a great conference, but it&rsquo;s so huge that it&rsquo;s hard to make a real connection there.</p>

<p>The speakers for the conference also included a bunch of local experts, so I
got to put some faces to some names that I have seen float past on the local
<a href="http://cocoaheads.org/us/PortlandOregon/index.html">CocoaHeads</a> mailing list.
Janine Ohmer (<a href="http://twitter.com/janineanne">@janineanne</a>), who manages that
mailing list, gave a great talk on everything to do with making an app
<em>except</em> the coding (including such favorite developer pastimes as Marketing
and Documentation). Justin Miller (<a href="http://twitter.com/incanus77">@incanus77</a>)
of <a href="http://www.mapbox.com/">MapBox</a> had a nice overview of MapKit APIs and
also showed off some <a href="http://www.mapbox.com/">MapBox</a> tools that can be useful
when you need to go beyond what MapKit offers.</p>

<p>There were lots of other great sessions, too, and my notes from them go on for
thousands of words, but here&rsquo;s a short list of some of the most memorable
pieces of advice I picked up:</p>

<ul>
<li>Not everyone will be delighted with your work, but your app is not for
everyone - Daniel Steinberg
(<a href="http://twitter.com/dimsumthinking">@dimsumthinking</a>)</li>
<li>You can typdef Objective-C blocks and set up blocks as properties to make<br/>
them convenient to pass around in your APIs - Daniel Steinberg
(<a href="http://twitter.com/dimsumthinking">@dimsumthinking</a>)</li>
<li>If you have some bits of data that you need to persist across a
delete/restore of your app, you can put them into the keychain - Walter Tyree
(<a href="http://twitter.com/walterpt">@walterpt</a>)</li>
<li><a href="http://www.mapbox.com/">MapBox</a> has some handy tools for making maps work
offline - Justin Miller (<a href="http://twitter.com/incanus77">@incanus77</a>)</li>
<li>You can add your own storage implementations to Core Data and do some wild
and interesting (and possibly even useful) things - Jonathan Penn
(<a href="http://twitter.com/jonathanpenn">@jonathanpenn</a>)</li>
<li>XCode&rsquo;s Storyboards are pretty useful and pretty awkward/painful at the same
time (I&rsquo;ve used them a bit, but apparently haven&rsquo;t hit the pain points yet;
hopefully things will get better since it seems like Apple is pushing
Storyboards these days) - Collin Donnell
(<a href="http://twitter.com/collindonnell">@collindonnell</a>)</li>
<li>NSCoding and NSValue will let you put pretty much anything into Core Data
with a modicum of effort - Walter Tyree (<a href="http://twitter.com/walterpt">@walterpt</a>)</li>
<li><a href="https://github.com/rentzsch/mogenerator">mogenerator</a> makes using Core
Data&rsquo;s model code generation tools much more convenient and practical - Walter
Tyree (<a href="http://twitter.com/walterpt">@walterpt</a>)</li>
<li>XCode lets you play a sound at a breakpoint, which is handy for when you
need to hear when or how often something is happening without interrupting
your code - Kyle Richter (<a href="http://twitter.com/kylerichter">@kylerichter</a>)</li>
<li>When making an iPhone app, you only have about 11 characters for the name
before it starts getting cut off on the home screen -
Janine Ohmer (<a href="http://twitter.com/janineanne">@janineanne</a>)</li>
<li>You can use Data Detectors in iOS to clean up poorly formatted data you
ingest from somewhere else and turn it into nice structured data - Colin
Cornaby (<a href="http://twitter.com/colincornaby">@colincornaby</a>)</li>
</ul>


<p>One final note of awesomeness: Jean MacDonald
(<a href="https://twitter.com/macgenie">@macgenie</a>) was running
<a href="http://www.appcamp4girls.com">App Camp for Girls</a> for the first time this
summer, and brought some of girls to the conference. They added immeasurably
to the roundtable discussion on Women in Tech, and I hope they got a lot out
of the conference (in addition to the books that I heard the fine folks from
<a href="http://www.bignerdranch.com">Big Nerd Ranch</a> gave them!).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Things I Learned: Git Add Your Gem's Generator Files]]></title>
    <link href="http://octothought.com/things-i-learned-git-add-your-gems-generator-files/"/>
    <updated>2013-06-03T18:15:00-07:00</updated>
    <id>http://octothought.com/things-i-learned-git-add-your-gems-generator-files</id>
    <content type="html"><![CDATA[<h2>Background</h2>

<p>I&rsquo;ve been spending some of my free time creating a Ruby Gem for Rails apps that
makes it easy to set up tables with fixed data that you want to always be
present in your database: <a href="http://rubygems.org/gems/static-data">static-data</a>.
This is handy for lookup tables, predefined category lists, and other such
things.</p>

<h2>The Problem</h2>

<p>I created some new files to add a new rails generator to static-data, I built and
installed my gem, and&hellip; nothing. In researching other people&rsquo;s challenges
in getting their generators to work, I tried moving my generator file all over the
place. I even tried adding extra code to my railtie to tell Rails where the
generator file was, but that just caused <code>rails generate</code> to blow up entirely when it
couldn&rsquo;t find my generator file.</p>

<!-- MORE -->


<p>After scratching my head for more than a few minutes, I
hacked up an existing gem that <em>was</em> showing up in <code>rails generate</code>, tracked
down the code that attempts to require generator files (which contains a
rescue clause that swallows <em>all</em> errors in a generator being required&mdash;bad code! no biscuit!), and
eventually figured out that my generator file wasn&rsquo;t even included in the
installed gem files!</p>

<h2>The Solution!</h2>

<p>Then it dawned on me: the gemspec for my static-data gem is set up to populate the
gem&rsquo;s file list from <code>git ls-files</code>, but since I&rsquo;d set that up a few weeks ago (I
don&rsquo;t have <em>much</em> free time, and it tends to come in small, infrequent chunks),
I had totally forgotten that little&mdash;but very important&mdash;detail.</p>

<p>Once I did a <code>git add lib/generators</code> in my gem repository, rebuilt and
reinstalled my gem, the generator was finally listed in <code>rails generate</code> and
with a few tweaks to my template, my generator was in business.</p>

<p>Apparently this particular gotcha isn&rsquo;t biting too many other people, since no
one ever mentioned this in my search for clues on the interwebs. Nevertheless, I am
writing this detail down so hopefully the next person with this issue won&rsquo;t
have to scratch their head for quite as long as I did.</p>
]]></content>
  </entry>
  
</feed>
