Hi All
In my application,i have a form which contains a select box for
“categories”
And when the user selects a category,a remote function is called which
fetches a list of subcategories and populates in another select box on
the form
Category:<%= collection_select :category, :id,
@categories, :id , :name, {}, {:size => 10, :onchange =>
remote_function( :update => "subcat", :url => { :controller =>
"categories", :action => "get_subcategories"}, :position => "replace",
:with => "'category_id='+this.value" ) } %>
I have a div with id "subcat" on the form.
I also have set a session timeout of 10 mins.
I am getting my page redirected to login page if not the session is
present/timed out.I am doing this by having the function called
“login_required” in the application.rb controller and in all controllers
I am adding
before_filter :login_required
But this is working only in case of Normal Http requests.
In the above case,if the session has expired,and the user is trying to
populate the subcategory list using remote call,I am getting the error
message updated in the div with id subcat .
But I want the page to be redirected to login page,even when there are
remote calls to the function if session has timed out.
I am in need of a solution at the earliest.Kindly help me
Thanks
Charanya
Thanks Denis…
this really helped…
You can specify Javascript callbacks for the various phases of the
remote call and also for specific response status or status codes (see
the doc for link_to_remote at http://tinyurl.com/s47df ; remote_function
takes the same arguments).
So it might be something like this (off the top of my head):
remote_function( :update => “subcat”, :url => { :controller =>
“categories”, :action => “get_subcategories”}, :position => “replace”,
:with => “‘category_id=’+this.value”, 302 =>
“handleRedirection(request)” )
where handleRedirection() is a Javascript function you’ve written to do
the redirection (I’m assuming the response Lcation: header is available
there, but haven’t checked).
hth,
dwh