I am currently doing a project, and I am using Devise
for the User Authentication
. I have the before_action :authenticate_user!
in my Post Controller
. When I click new post
without Signing in
it redirects to the Log in
Page. That's fine, But I want it to be as pop over(when I click the new post
,the log in
form must popover). How can I achieve this. I have also referred to this
Rails 4 Devise Login as a POPUP window
But, still when I clicked the new Post
, it is redirecting to the sign in
page.
Help me with this issue, Thanks in advance.
I have this code in my Users::SessionsController < Devise::SessionsController is
class Users::SessionsController < Devise::SessionsController
respond_to :json
def create
session['user_auth'] = params[:user]
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#failure")
sign_in(resource_name, resource)
message = I18n.t 'devise.sessions.signed_in'
yield resource if block_given?
if request.xhr?
return render :json => {:success => true, :login => true, :data => {:message => message}}
else
respond_with resource, location: after_sign_in_path_for(resource)
end
end
def failure
user = User.where(email: session['user_auth'][:email]).first rescue nil
message = I18n.t 'devise.failure.invalid', authentication_keys: "email"
respond_to do |format|
format.json {
render :json => {:success => false, :data => {:message => message, :cause => 'invalid'} }
}
format.html {
redirect_to '/users/sign_in'
}
end
end
end