title: Devise RegistrationsController create action in API
body: <p>I'm trying to create a Rails 3 app with an API. I use Devise as my authentication system. I would like to make it possible to sign up and later sign in through the API. And i'm not quite sure how I should do this. I have created separated controllers to manage the API, i.e. <code>api/v1/account/1/projects.json</code>. I'm currently trying to create a custom <code>Devise::RegistrationsController</code> for the API, but I'm not quite sure how to do this. </p>
  
  <p>My create action currently looks like this:</p>
  
  <pre><code>class API::V1::RegistrationsController &lt; Devise::RegistrationsController
    redpond_to :json, :xml
  
    def create
      build_resource
      if resource.save
        if resource.active_for_authentication?
          # Account is a nested resource for User, I want to 
          # create an associated account when the User signs up through the client, 
          # how should I do this?
          account = resource.accounts.build 
          # How can I get the sign_in to work?
          sign_in(resource_name, resource)
          # Probably wrong
          respond_with resource, :location =&gt; after_sign_up_path_for(resource)
        else
          # probably wrong
          expire_session_data_after_sign_in!
          respond_with resource, :location =&gt; after_inactive_sign_up_path_for(resource)
        end
      else
        # probably wrong, or?
        clean_up_passwords resource
      end
    end
  </code></pre>
  
  <p>Which probably is very incorrect as mentioned in my comments, so I wonder if anyone could give me any guidance on how to make it work. Should also mention that account is a nested resource for the user.   </p>
  
  <p>I also wonder how I should set up the login and logout functionality in the API with Devise. </p>
  
  <p>Thanks! </p>