title: How to use rails paths in js files for GET's and ajax calls?
body: <p>I have a link that toggles description lengths between short and long.</p>
  
  <p>Initially I created it with a call from a js file, i.e. just</p>
  
  <pre><code># /app/assets/javascripts/toggle_length.js
  $.get('/toggle_full_details');
  </code></pre>
  
  <p>That works fine. (it uses css classes to show/hide long and short descriptions).</p>
  
  <p>But ideally I want to use a rails route for the link.</p>
  
  <p>Which are (partial listing for relevant route):</p>
  
  <pre><code>$ rake routes
      Prefix               Verb  URI Pattern                     Controller#Action
      ...
      toggle_full_details  GET   /toggle_full_details(.:format)  links#toggle_full_details
      toggle_row_shading   GET   /toggle_row_shading(.:format)   links#toggle_row_shading
      ...
      root                 GET   /                               links#index
  </code></pre>
  
  <p>So I renamed my <code>long_or_sort_details.js</code> file to be <code>long_or_short_details.js.erb</code> and tried using a rails route but none of the below attempts worked, what am I missing / doing wrong?</p>
  
  <pre><code>$.get({ "&lt;%= toggle_full_details_path %&gt;" }) 
  // Gave: undefined local variable or method toggle_full_details_path
  
  $.get({"&lt;%= toggle_full_details_url %&gt;"}); 
  // Gave: undefined local variable or method toggle_full_details_url
  
  $.ajax({url:"/toggle_full_details", type: 'GET' }) 
  // Works ok... but not using routes :(
  
  $.ajax({ url:'&lt;%= toggle_full_details_path %&gt;', type: 'GET' }) 
  // undefined local variable or method `toggle_full_details_path'
  </code></pre>
  
  <p>fyi my <code>app/assets/javascripts/applications.js</code> includes the file with</p>
  
  <pre><code>//= require long_or_short_details
  </code></pre>