title: Ruby on Rails - Send JavaScript variable from controller to external Javascript asset file
body: <p>I am creating a website in Ruby on Rails.  I have a controller action that renders a view like so:</p>
  
  <pre><code>def show
    time_left = Time.now.to_i - 3.hours.to_i
    @character = current_user.characters.find(params[:id])
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml =&gt; @character }
    end
  end
  </code></pre>
  
  <p>This is fine as it renders the show.html.erb as I like.  I would like however to somehow pass time_left to the view as a Javascript variable as this value is use by a countdown JQuery plugin.</p>
  
  <p>I could put a javascript block on the page in the HTML and print a instance variable out like so:</p>
  
  <pre><code>&lt;script type="javascript"&gt; $('#countdown').countdown('&lt;%= @time_left =&gt;')&lt;/script&gt;
  </code></pre>
  
  <p>But I would like to keep all my JS in a external file and off the page could anyone give some advice on how to implement this?</p>