Rails 3: How to "redirect_to" in Ajax call?
Finally, I just replaced
redirect_to(:controller => 'jobs', :action => 'index')
with this:
render :js => "window.location = '/jobs/index'"
and it works fine!
There is very easy way to keep the flash for the next request. In your controller do something like
flash[:notice] = 'Your work was awesome! A unicorn is born!'flash.keep(:notice)render js: "window.location = '#{root_path}'"
The flash.keep
will make sure the flash is kept for the next request.So when the root_path
is rendered, it will show the given flash message. Rails is awesome :)
I think this is slightly nicer:
render js: "window.location.pathname='#{jobs_path}'"