json と ajax を使用して Rails api 認証の次のチュートリアルを使用しようとしました: http://jessehowarth.com/devise
動作しているように見えますが、入力したログイン資格情報 (既存および非存在) に関係なく、送信を押すたびに失敗します。
node.jsを使用してリクエストを行います
var post_data = querystring.stringify({
      'email' : 'foo@bar.com',
      'password': 'foo',
      'remember_me': 1
  });
  var options = {
    host: 'localhost',
    path: '/users/sign_in.json',
    port: '3000',
    method: 'POST'
  };
  callback = function(response) {
    var str = '';
    response.on('data', function (chunk) {
      str += chunk;
    });
    response.on('end', function () {
      console.log(str);
    });
  }
  var req = http.request(options, callback);
  req.write(post_data);
  req.end();
私のdevise-sessionコントローラは次のようになります:
class SessionsController < Devise::SessionsController
  def create
    respond_to do |format|
      format.html{ super }
      format.json do
       resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
       return sign_in_and_redirect(resource_name, resource)
      end
    end
  end
  def sign_in_and_redirect(resource_or_scope, resource=nil)
    scope = Devise::Mapping.find_scope!(resource_or_scope)
    resource ||= resource_or_scope
    sign_in(scope, resource) unless warden.user(scope) == resource
    respond_to do |format|
      format.json {render :json => {:success => true, :redirect => stored_location_for(scope) || after_sign_in_path_for(resource)}}
      format.html {redirect_to root_url}
    end
  end
  def failure
    respond_to do |format|
      format.json { render:json => {:success => false, :errors => ["Login failed."]} }
    end
  end
end
私が得る出力:
{"success":false,"errors":["Login failed."]}
これに関するアドバイスはありますか?
ありがとう!