in views, there are idiom like this for #create and #update actions
<% if @article.errors.any? %>
<div id="error_explanation">
<h2>
<%= pluralize(article.errors.count, "error") %> prohibited
this article from being saved:
</h2>
<ul>
<% @article.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
Now, is there similarly a way to check in the Users::SessionsController < Devise::SessionsController, whether the user-login was successful or not?
There is a similar thread here Ruby on Rails Devise code after login but the answer by Peter P. Jan 18 '15 at 3:06 suggests, that exactly when the login is unsuccessful, then the before_action "will not be run", which is bad, because I need exactly this information, whether the login was unsuccessful.
The accompanying code is
# app/controllers/custom_sessions_controller.rb
class CustomSessionsController < Devise::SessionsController
## for rails 5+, use before_action, after_action
before_filter :before_login, :only => :create
after_filter :after_login, :only => :create
def before_login
end
def after_login
end
end
But obviously useless towards my problem... (?)
The suggestions are to use Warden hooks like this by User Mike Lapinskas, Oct 8 '16 at 5:33, but the content too doesn't seem to be an answer to my problem. It is about after login, not a test whether the login was unsuccessful
class User < ApplicationRecord
Warden::Manager.after_set_user do |user, auth, opts|
if (opts[:scope] == :user && opts[:event] == :set_user)
# < Do your after login work here >
end
end
end
The approach in this thread Devise: redirect on sign up failure? seems promising
The hint to Devise::FailureApp led me to https://gist.github.com/emilsoman/5604254, also see Custom Devise 401 unauthorized response
The responses mentioned there are all JSON. Is this mandatory? Can't I just call render on an html.erb-template/partial ?
Thanks