title: Rails 4: Reload page with ajax after submitting remote form to a different controller
body: <p>I've made a comments section for my 'posts' views and I've got <code>remote: true</code> working on the form so when you hit enter and submit the 'new comment' form to the database, it updates in the background fine (the comment is created, page doesn't redirect or change) but I can't get it to load the comments on the page. You have to refresh the page to see them. </p>
  
  <p>I could do <code>redirect_to :back</code> in the comments controller after saving but that takes user to top of the page rather than staying put to see the comment appear. </p>
  
  <p>I've tried <code>render 'posts#show'</code> after saving the comment in the comment controller create action but that tries to send you to <code>/comments/posts/:slug/</code>. If it actually rendered the posts show action I think this would work.</p>
  
  <p>Comments controller:</p>
  
  <pre><code>class CommentsController &lt; ApplicationController
    before_action :find_commentable
  
    def show
    end
  
    def new
      @comment = Comment.new
    end
  
    def create
      @comment = @commentable.comments.new comment_params
      @comment.author = current_user if current_user
      @comment.save
    end
  
    private
  
      def comment_params
        params.require(:comment).permit(:body, :author_id, :post_id)
      end
  
      def find_commentable
        @commentable = Comment.find(params[:comment_id]) if        params[:comment_id]
        @commentable = Post.find_by_slug(params[:post_id]) if params[:post_id]
      end
    end
  </code></pre>
  
  <p>Comment section on post show view:</p>
  
  <pre><code>%ul#post-comments
    = render 'comment_feed'
  
    = form_for [@post, Comment.new], remote: true do |f|
      = f.text_field :body, class: 'js-new-comment-field', placeholder: "Write a comment..."
  </code></pre>
  
  <p>posts/show.js.erb:</p>
  
  <pre><code>$("#post-comments").html("&lt;%= escape_javascript render("comment_feed") %&gt;");
  </code></pre>
  
  <p>Routes.rb:</p>
  
  <pre><code>  resources :posts do
      collection do
        match 'search' =&gt; 'posts#search', via: [:get, :post], as: :search # For ransack search
      end
      resources :comments
    end
  
    resources :comments do
      resources :comments # Replies on comments
    end
  </code></pre>