title: Rails: ajax form submission return new object
body: <p>So I'm making a rails website. I have a remote form_for tag that creates a new issue through ajax call when I click the submit button. I want the rails app to add that new issue back to the browser javascript variable, the collection of issues.
  Right now I have</p>
  
  <pre><code>----issues_controller.rb-----
  def create
      @issue = @project.issues.new(issue_params)
      @issue.user_id = current_user.id
  
      respond_to do |format|
        if @issue.save
          format.html { redirect_to [@project, @issue], notice: 'Issue was successfully created.' }
          format.js
          format.json { render :show, status: :created, location: @issue }
        else
          format.html { render :new }
          format.json { render json: @issue.errors, status: :unprocessable_entity }
        end
      end
    end
  
  ----create.js.erb----
  var old_issues = $('#issues').data('issues');
  old_issues += $.parseJSON(&lt;%= @issue.to_json =&gt;);
  </code></pre>
  
  <p>I've heard that if you are using to_json method then you are doing it wrong. What's the more appropriate way of doing this?</p>