I’m using ROR 1.0 and the included prototype.js to do some AJAX stuff.
I’m using the form_remote_tag to submit a login form using AJAX.
So, any error/failed login will be displayed using AJAX. But, for
successful login, I would want it to reload the wholepage, not just
update the
.
How can I achieve this?
On 1/4/06, ngising [email protected] wrote:
I’m using ROR 1.0 and the included prototype.js to do some AJAX stuff.
I’m using the form_remote_tag to submit a login form using AJAX.
So, any error/failed login will be displayed using AJAX. But, for
successful login, I would want it to reload the wholepage, not just
update the
.
How can I achieve this?
change the page with javascript. In the :success callback of your
form_remote_tag, do something like “location.href = ‘foo’”
–
rick
http://techno-weenie.net
ok I got it…
render :nothing => true, :status => 401
change the page with javascript. In the :success callback of your
form_remote_tag, do something like “location.href = ‘foo’”
But what about the failure case ? Should I set a response of HTTP to
something other than 200 in the controller?so that I can handle it via
the
failure callback of the Ajax class in the javascript?
Hi Carlos,
Thanks for the example…Thats what I was looking for .Just one small
thing.
Whats the false parameter you pass to window.location.reload(). I
actually
want to do something like redirecting to the user’s homepage if the
password/username is correct.
So I suppose something like this should work.
document.href=’/matters_crud/home’
Vivek
Hi Vivek
I think the solution you are looking for is what Jamis B. teached me a
few
weeks ago:
…
When I’ve needed something like this, I will typically manage things
manually. Instead of specifying the :update element, I will handle
all of that in a :complete handler by hand. The :complete handler
checks the value of a custom header (‘X-What-To-Do’, for example). If
the header is ‘error’, then I update the ‘ajax_div’ element with the
request.responseText data. If the header is ‘ok’, then I execute
window.location.reload(false).
Does that make sense? If not, let me know and I can post a more
detailed example.
here’s a snippet from the hypothetical RHTML file:
<%= form_remote_tag :complete=>'handleComplete(request)',
:url=>{:controller=>'matters_crud',
:action =>:update,
:id => @matter} %>
<%= render_partial 'form' %>
<%= submit_tag 'Edit' %>
Then, in your controller, you just do:
def update
@matter = Matter.find(params[:id])
if @matter.update_attributes(params[:matter])
headers[‘X-Instruction’] = “ok”
render :nothing => true
else
headers[‘X-Instruction’] = “error”
render :partial => ‘error’
end
end
Hope that helps
Okada.
2006/1/5, Vivek K. [email protected]:
Hi all:
I’m doing something similar to this but for an account signup
controller. So once the user successfully creates an account, the user
is redirected to index.rhtml by
window.location.href = “http://localhost:3000”;
I have a problem where the session hash gets deleted on the first time
through the process, but not deleted on subsequent times. I’d like to
preserve session[:user_id] from a successful account creation/login, but
it never works the first time. I can see session[:user_id] = @user.id
being set in irb, but after the redirect session[:user_id] = nil. And
as previously stated, this works when I create a new account during the
same browser session.
Has anyone else had this problem?
Boram
I would have thought that RJS provides a much cleaner solution.
update.rjs:
if @matter.valid?
page << ‘location.reload(false);’
else
page.replace_html ‘ajax_div’, :partial => ‘error’
end
-Jonny.