title: Making an ajax request and returning success in rails action
body: <p>I'm trying to get some json from an action but I have a problem.</p>
  
  <p>I know that you can return "format.js" and return an ".js.erb" file but... Imagine I have an action that return some stuff and I want to work with that in two different ways. I cannot have that two different ways on the same .js.erb because when I return it, both ways will be executed, right? I mean, when I return that file, that file will be processed entirely.</p>
  
  <p>So I tried to use the jQuery way.</p>
  
  <p>I have:</p>
  
  <pre><code># GET /posts/slug/hidden_content.json
  def hidden_content
    @post = Post.find(params[:id])
    @post = hidden_post_part(@post.body)
  
    respond_to do |format|
      format.json { render json: @post, :status =&gt; :ok}
    end
  end
  </code></pre>
  
  <p>And in the controller.coffee:</p>
  
  <pre><code>$ -&gt;
    # Render hidden part of post
    $(".showallpost img").click( -&gt;
      post_url = $(this).next().attr("href").split("/").pop();
      $.ajax
        url: Routes.hidden_content_path(post_url),
        type: "GET",
        contentType: "application/json",
        success: (data) -&gt;
          console.log "foo"
    );
  </code></pre>
  
  <p>The GET works perfectly and it returns what I need but the success function is never called, I don't see the "foo" log.</p>
  
  <p>I guess that the action should return something to tell to the caller that the GET was successful. (I tried with :status without luck).</p>
  
  <p>So I can't work with my GET data.</p>
  
  <p>Ideas?</p>