title: Embed ruby inside javascript
body: <p>I am a complete newbie to the world of RoR.</p>
  
  <p>Although I have generated some code using rails scaffold. I am also able to post a form via ajax using the :remote => true.</p>
  
  <p>And the form gets posted, nice and clean!
  But I wish to render some data that was returned from my controller using link_to so that it creates a link to a route/resource.</p>
  
  <p>I have tried creating a .js.erb file and embedding the code in it, but it gives me an error saying:</p>
  
  <pre><code>undefined method `link_to'
  </code></pre>
  
  <p>code in .js.erb</p>
  
  <pre><code>$(document).ready(function(){
  
  
  $("#new_post").bind('ajax:success', function(xhr, data, status){ 
      console.log(data)
      if(data.errors){
          console.log("Error!")
      }
      else{
          var user_name = data.user; // json is contained in data variable        
          $("#recent_posts").prepend("&lt;%= j link_to(user_name, '#') %&gt;");
      }
  });
  
  });
  </code></pre>
  
  <p>Where am I going wrong?</p>