Big thanks to all replyers. I tried two different solutions inspired by your comments and ended up choosing the second one.
Make the call ajax and then redirect from the rendered js.erb template if login is successfull. Inspired by this answer: https://stackoverflow.com/a/5454887/1936629
Add a url parameter in case of failed login and open the modal window if this parameter exists.
The reason i chose the second option is because it refreshes the page in case of success or failure thus allowing me to use elements like the flash hash or active record error messages.
Thanks again