DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

How To Escape From AJAX URL

03.16.2006
| 17892 views |
  • submit to reddit
        From Dylan Stamat's post on the Ruby on Rails list 	


Within my "login.rjs" template that get's invoked after my login process, it returns to the same page with an error message on error, or... if the login was successful, it needs to "redirect" to another controller... which is pretty much impossible to do otherwise.  so, my " login.rjs" looks like:

if @logged_in_client
  page.replace_html "message", :partial => 'shared/bad_login'
else
  page.redirect_to "whatever you want here"
end
------ End Message--------
Here is my two cents:
Technically, you can do this without a RJS template at all, because it is such a simple example. Use this in your controller

render :update do |page|
  if @logged_in_client
    page.replace_html "message", :partial => 'shared/bad_login'
  else
    page.redirect_to "whatever you want here"
  end
end