title: Rails: Optional lookup fields
body: <p>In my Rails app I am using <strong>collection_select</strong> to provide a list of valid choices for the user. I stored only the <strong>id</strong> from the looked-up table. I then make a call to the looked-up class in the <strong>show</strong> view to retrieve the actual value for the id.</p>
  
  <p>in edit:</p>
  
  <pre><code>= f.collection_select :language_id, Language.find(:all, :conditions =&gt; ["supported = 't'"]), :id, :language, include_blank: false, :prompt =&gt; "Language"
  </code></pre>
  
  <p>in show:</p>
  
  <pre><code>%p
    %b Language:
    = Language.find(@article.language_id).language_code
  </code></pre>
  
  <p>This is all working fine unless no choice is made. If the <strong>@article.language_id</strong> field is null, the view cannot load as the <strong>find</strong> fails. Any suggestions on how to ignore null values and leave the field blank?</p>