ruby on rails - Ajax device authentication doesn't work? -


i tried use following tutorial rails api authentication using json & ajax: http://jessehowarth.com/devise

it seem work, no matter login-credentials enter (existing , non-existing), fails everytime hit submit.

i make request using 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(); 

my devise-session controller looks this:

class sessionscontroller < devise::sessionscontroller    def create     respond_to |format|       format.html{ super }       format.json        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 |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 |format|       format.json { render:json => {:success => false, :errors => ["login failed."]} }     end   end  end 

the output get:

{"success":false,"errors":["login failed."]} 

any advice on this?

thanks!

okay, fault. if silly me:

i used parameters email, password , remember_me instead of user[email], user[password] , user[remember_me]

solved!


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -