title: Ruby on Rails: Action without View
body: <p>I have what I think is a very simple problem. I'm coming from a PhP background, and used to do this all the time, so I may be looking at this the wrong way.</p>
  
  <p>I am trying to create an ajax handler in RoR. When the user clicks a button, javascript fires off a POST, and gives the user feedback using the "success:" parameter of jQuery's ajax function.</p>
  
  <p>The problem is, RoR is trying to load a view for the ajax handler, when I really just need a few lines in the controller to do the database work, and echo out a status code that will be interpreted by the user's javascript.</p>
  
  <p>This is all just a mailchimp subscribe holding page, so I am only using the 'home' controller.</p>
  
  <p>My Routes;</p>
  
  <pre><code>map.root :controller =&gt; 'home'
  map.connect '/mcsubscribe', :controller =&gt; 'home', :action =&gt; 'mcsubscribe'
  </code></pre>
  
  <p>My Home Controller;</p>
  
  <pre><code>class HomeController &lt; ApplicationController
    def index
      # no content
    end
    def mcsubscribe
      print params[:email]
    end
  end
  </code></pre>
  
  <p>And my testing javascript, just so you understand what's going on;</p>
  
  <pre><code>function mcSubscribe() {
      var email = jQuery("#signup_input_email").val();
      jQuery.ajax({
          type: "POST",
          url: "http://domain.com/mcsubscribe",
          data: "email=" + email,
          cache: false,
          success: function(result) {
              alert(result);
          }
      });
  }
  </code></pre>
  
  <p>I thought this would be a common problem, but I've googled around and only managed to find suggestions to redirect, as the user will never visit the /mcsubscribe page, that doesn't seem appropriate.</p>