title: Rails - Refresh view after submit from different controller
body: <p>I'm having trouble refreshing a view after a form submit creates an Item on a different controller than the current view.</p>
  
  <p>I have 2 models, Users and Items. The Users have multiple Items.</p>
  
  <p>The Users 'show' view lists all of its Items.  In the view I have a partial for rendering all the items into separate table rows:</p>
  
  <pre><code>&lt;table class="items"&gt;
            &lt;%= render @items%&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>In the same view I have a div at the bottom that is used for creating new Items, this div contains a Items partial (which contains a form for creating new Items):</p>
  
  <pre><code>&lt;div id="new_item_dialog"&gt;
      &lt;%= render :partial =&gt; '/items/new_items' %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This 'new_item_dialog' div is popped up into a dialog via jquery, and has :remote => true to perform the Item 'create' async: </p>
  
  <pre><code>$('#open-dialog').click(function(){
      $item_dialog.dialog('open');
  });
  
  $('.item_submit').click(function(){
      $item_dialog.dialog('close');       
  });
  </code></pre>
  
  <p><strong>The problem I'm running into is refreshing the User's 'show' page after the new Item has been submitted.</strong>  </p>
  
  <p>A simple redirect_to the User's show page from the Item's 'create' controller doesnt refresh the data</p>
  
  <pre><code>  def create
      @user = cur_user
      @item = @user.items.build(params[:item])
      if @item.save
        redirect_to @user
      else 
        render 'new'
      end
  </code></pre>
  
  <p>I've also tried to use jQuery to load the new data:</p>
  
  <pre><code>$('.new_item').bind('ajax:success', function()
  {
      $.get('/items/new_item', function (html) {
                 $('.items').html(html);
             });
  });
  </code></pre>
  
  <p>But I get the error message:</p>
  
  <pre><code>ActionView::MissingTemplate (Missing template items/show with 
  </code></pre>
  
  <p>Any help would be greatly appreciated!</p>
  
  <p>Note: I've also tried a 'render @user' after the Item gets saved in the Item's 'create' controller, to re-render the User's 'show' view, but I get the same "MissingTemplate" error as above.</p>
  
  <p><strong>Updated:</strong>
  Also tried:</p>
  
  <pre><code>def create
      @user = cur_user
      @task = @user.item.build(params[:item])
      if @item.save
        render :partial =&gt; "items/item"
  </code></pre>
  
  <p>And (replacing the render in the above controller)</p>
  
  <pre><code>render :partial =&gt; @item
  </code></pre>
  
  <p>And</p>
  
  <pre><code>render :partial =&gt; 'views/items/item', :collection =&gt; @user.items
  </code></pre>
  
  <p>And</p>
  
  <pre><code>render :partial =&gt; 'views/items/item', :locals =&gt; { :variable =&gt; @item}
  </code></pre>
  
  <p>And</p>
  
  <pre><code>render :action =&gt; 'users/show', :layout =&gt; 'users'
  </code></pre>
  
  <p>Everyone of these returned the error:</p>
  
  <pre><code>ActionView::MissingTemplate (Missing template ..... with {:locale=&gt;[:en, :en], :formats=&gt;[:js, :"*/*"], :handlers=&gt;[:rhtml, :rxml, :builder, :erb, :rjs]} in view paths "test/app/views"):
    app/controllers/items_controller.rb:11:in `create'
  </code></pre>
  
  <p>With Ajax like this: (doesnt ever get used though, everything fails on the rendering of the partial)</p>
  
  <pre><code>$('.new_item').bind('ajax:success', function()
      {
          $.ajax({
                success: function(html){
                  $(".items").html(html);
                }
          });
      });
  </code></pre>