title: Rails 4: Redirect to another action with js
body: <p>in my app I have show action with show.html.erb page, where I show the recipe and the comment for this recipe. and I wand add the ajax functionality to comment adding. in controller RecipeController I have add_new_comment action. can I from add_new_action redirect to show action from format.js?</p>
  
  <p><strong>show</strong> action:</p>
  
  <pre><code>def show
    @category = Category.where(id: @recipe.category_id).take
    @comments = @recipe.comments.recent.all.paginate(page: params[:page], per_page:15)
  end
  </code></pre>
  
  <p><strong>add_new_comment</strong> action:</p>
  
  <pre><code>def add_new_comment
    @recipe = Recipe.find(params[:recipe_id])
    if params[:comment].present?
      @comment = @recipe.comments.build
      @comment.comment = params[:comment]
      @comment.user = current_user
      respond_to do |format|
        if @comment.save
          format.html {redirect_to recipe_path(@recipe)}
          format.js {render action: 'show', :id =&gt; @recipe.id}
        end
      end
    end
  end
  </code></pre>
  
  <p>and I have <strong>add_new_comment.js.erb</strong></p>
  
  <pre><code>$('#comments').html("&lt;%= j (render 'comments') %&gt;");
  </code></pre>