title: Reading variable value from Rails controller in view for Rails
body: <p>I have an instance variable, @source_code in my Rails controller that I want to retrieve in my Ajax response via the success function. I am calling this Ajax function from my index.html.erb file and it renders a show.html.erb file. I want to get my text area to print out the @source_code.code value.</p>
  
  <p>SourcesController.rb</p>
  
  <pre><code> def show
    Rails.logger.debug("REACHED: show &gt;&gt;")
    @source_code = Source.find_by(id: params[:id])
    Rails.logger.debug("REACHED: source_code &gt;&gt;" + @source_code.code.to_s)
    @sources = Source.all
   end
  </code></pre>
  
  <p>index.html.erb</p>
  
  <pre><code> function updateTextArea(source_id){
    console.log(source_id);
    $.ajax({
      type: "GET",
      url: "/sources/" + source_id,
      data: {source_id: source_id},
      success: function (response){
        alert("Ajax success")
        console.log("&lt;%= @source_code %&gt;");
        editor.session.setValue("&lt;%= @source_code %&gt;");
      },
      error: function(){
       alert("Ajax error!")
      }
   });
  </code></pre>