title: Adding to database without refreshing the page?
body: <p>When I add a model in my index action, the create action is invoked that adds an instance of the model to the database. This is the following create action: </p>
  
  <p>tracks_controller.rb</p>
  
  <pre><code>def create
      @track = Track.new(params[:track])
  
  
      if @track.save
          redirect_to(root_url) //Want to change this!
      else 
          @tracks = Track.all
          render :action=&gt;"index"
      end
  end
  </code></pre>
  
  <p>Where you can see that I am redirected to my root url (where I want to be) everytime create is invoked. However, how can I carry this out without refreshing the page? Since tracks are being played, I do not want the page to be refreshed whenever something is added to the database.</p>
  
  <p>If I change this line to <code>render :action=&gt;"index"</code>, then I receive the following error in my <code>index.html.erb</code> file</p>
  
  <p><code>undefined method</code>each' for nil:NilClass`</p>
  
  <pre><code>15: &lt;p&gt;Database is empty!&lt;/p&gt;
  16: &lt;%else%&gt;
  17: &lt;br&gt;
  18: &lt;% @tracks.each do |track| %&gt;
  19: &lt;div id="list_container"&gt;
  20:     &lt;ul&gt;
  21:         &lt;li class="list_container"&gt;
  </code></pre>
  
  <p>How do I go about achieving this?</p>