私がやろうとしているのは、ajax経由でログインすることですが、認証が失敗した場合は(エラーで)フォームを返します。デフォルトでdevise
は、一般的なエラーが返されます。これが私のコントローラーです:
class SessionsController < Devise::SessionsController
respond_to :js
def new
self.resource = build_resource(nil, :unsafe => true)
clean_up_passwords(resource)
render_user_form(resource, false)
end
def create
self.resource = warden.authenticate!(scope: resource_name, recall: "#{controller_path}#new")
sign_in(resource_name, resource)
render_user_form(resource, true)
end
def render_user_form(resource, success)
render json: {
success: success,
content: render_to_string(partial: 'users/login_form', locals: { user: resource })
}
end
end
new
ここでアドバイスされているように、アクションcreate
はから取得され、カスタマイズされます:デバイスのカスタムサインインDevise::SessionsController
しかし、これはエラーを返します:
"You need to sign in or sign up before continuing."
私のjs:
$('#login-form').bind 'ajax:success', (xhr, data, status) ->
alert data.content
誰かがこれを正しく構造化するのを手伝ってくれますか?