0

When I move to page which should be accesible only for signed in user, the Devise render sign in form. I have a nice styled notification which tells user that he is signed out, and I would like to show it without redirecting to sign in page. I have file user.js.erb which contains working Javascript code, but I don't know how to run it. I was trying to rewrite the authenticate_user method, but without success.

def authenticate_user!
  unless current_user

  end
end

I've tried respond_to with format.js, but it hasn't worked. I don't need ready code, but I would really appreciate if anyone can direct me in the right direction.

mparkitny
  • 1,165
  • 1
  • 9
  • 16

1 Answers1

0

To do this you need to authenticate user via ajax. There is no other way because when you press on 'login' or submit button, browser sends data to server and waiting for html reply that your server generates.

Please, check out this post.

Community
  • 1
  • 1
axvm
  • 1,876
  • 2
  • 11
  • 19
  • I haven't described my problem well enough, sorry. I edited my question. So basically I don't want to show sign in form at all. I want to show notification that the user isn't sign in without redirecting to any page. Thanks for help anyway. – mparkitny Jan 12 '16 at 00:47
  • @Garbus then set onclick callback on 'login' button to function that will perform ajax request to server and if server response says that credentials are wrong - show your notification. Here is useful post about how to do it, almost like you need. https://hackhands.com/sign-users-ajax-using-devise-rails/ – axvm Jan 12 '16 at 00:53