0

This is the code for my ajax call

var data = {user: {password: password, email: email}};
$.post('auto_login',data,function(res){
  if(res.success){
    // successfully logged in
  }
  else{
    // failed log in
  }
});

This is the code in my controller

def auto_login
  @user = parmas[:user]

  # how do i invoke login here...
  # res = Sessions.new(@user)
  # x = true if res.save

  respond_to do |format|
    format.json{ render :json => { :success => x } }
  end
end

I am doing this because I have a button which if a unregistered user clicks it will pop-up a modal window which ask for login info or register to the site. After the user fills up the required information, and if the system recognize that the data are valid, it will automatically redirect the user to a particular url.

Any help will do.

Thank you.

4

1 回答 1

0

Devise 允许您将登录表单放在任何地方。您可以将其放在部分中或使用 javascript 显示/隐藏。只需按照以下说明操作:

https://github.com/plataformatec/devise/wiki/How-To:-Display-a-custom-sign_in-form-anywhere-in-your-app

于 2013-03-13T04:18:34.643 回答