ruby on rails - Cannot get devise ajax to work -
what trying login via ajax, homecoming form (with errors) if authentication failed. default, devise
homecoming generic error. here controller:
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
actions taken devise::sessionscontroller
, customised, advised here: custom sign in devise
yet returns error:
"you need sign in or sign before continuing."
my js:
$('#login-form').bind 'ajax:success', (xhr, data, status) -> alert data.content
can help correctly structuring this?
trick alter devise config , register:
config.http_authenticatable_on_xhr = false config.navigational_formats = ["*/*", :html, :json]
ruby-on-rails devise
No comments:
Post a Comment