简体   繁体   中英

Updating modal popup (facebox) with ajax in rails

I am trying to make a sign in page (in rails 3) where a modal dialog pops up (facebox) when the user clicks on a "sign in" link. I have everything working without ajax and without the modal pop up.

I'm trying to implement this by doing the following:

  1. Show modal pop up containing a sign in form when user clicks "sign in"
  2. Perform ajax post in rails via (remote: => true)
    1. If credentials are good, login user and redirect to home page
    2. if credentials are bad, show the flash message and reset the sign in form modal pop up

The part I'm stuck on is the very last part, showing the flash message and resetting the sign in page in the model pop up.

How do I do this last step?

Edit:

I understand from the comments that I need to send the flash message as json to my view and I know how to do that (json response in the controller). But how do I wire things up so I can show the flash message and reset the form in the modal without reloading the whole page?

If you are submitting form through Ajax (:remote => true) then you can send the JavaScript response from the server on validation fails. This response will display the error messages. If you have any further query then go ahead :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM