title: Accessing a Model from js.erb file when precompiling
body: <p>I have a Rails 3 app where I am trying to populate a javascript variable with every Nation in my database (less than 300 nations) as a JSON object.  This is the relevant line in my <code>nations.js.erb</code> file:</p>
  
  <pre><code>_this.nations = &lt;%= Nation.all.to_json :only =&gt; [:id], :methods =&gt; :text %&gt;;
  </code></pre>
  
  <p>When I call my js file in a browser, <code>/assets/users.js</code> which does a require of the nations file, the <code>_this.nations</code> variable is populated perfectly. When I try to do a precompile I get the following:</p>
  
  <pre><code>$&gt; rake assets:precompile
  $&gt; rake aborted!
  uninitialized constant Nation (in nations.js.erb)
  </code></pre>
  
  <p>So my question is this: is it possible to reference the <code>Nation</code> model, or any model, from within the <code>js.erb</code> file for precompiling?  I also tried using my <code>NationsHelper</code> but my error just changed to uninitialized constant NationsHelper.</p>
  
  <p>I'm fairly new to RoR so if relevant information is needed that I haven't provided, please just ask.</p>