About filter

Hello:
I have a filter mehtod defined in the application.rb for
before_filter,and a method(create_action invoked in thhe ajax link)using
the filter.When authorize’s redirect_to happens and the create_action’s
codes don’t execute,the login template is inserted to the dom element
whose id is side.But i don’t want that result.In this case i want the
browser to redirect to the login action rendering in the login layout
instead of a remote insert.I want filter to work like this for the
remote link while still working unchangeably for many normal link. How
do i modify it?
###############################
def authorize
unless session[:login] && User.find_by_id(session[:login])
flash[:login]=“您还没登录或注册为用户”
redirect_to(:controller=>“login”,:action=>“login”)
end
end
##########################
<%form_remote_tag(:update=>“side”,:url=>{:action=>“create_action”},:method=>:post)do-%>

not use the ajax to resolve it?
i need your help!

On Aug 11, 5:58 am, Guo Y. [email protected]
wrote:

not use the ajax to resolve it?
i need your help!

As you’ve found, if you do a redirect then the redirected content is
inserted into the DOM (the javascript handling the ajax update never
sees the redirect. if you were using rjs (ie if your form_remode_tag
didn’t have the :update option) then you could do an rjs update, but
you’re not, so that won’t work either.
If you don’t want to change the form_remote_tag, one way out is to
have the ajax call’s onComplete check for a certain header field, and
if it is present, redirect (client side) to the login page. In your
filter if you detect that the request is an ajax one then instead of
redirecting them to the login page just set that magic header and
render nothing.

Fred

if you were using rjs (ie if your form_remode_tag

didn’t have the :update option) then you could do an rjs update, but
you’re not, so that won’t work either.

you mean that if i use rjs update,i can manage it? but how ? how to keep
the ajax and redirect to exist for the filter?

thank you!

On 11 Aug 2008, at 10:23, Guo Y. wrote:

if you were using rjs (ie if your form_remode_tag

didn’t have the :update option) then you could do an rjs update, but
you’re not, so that won’t work either.

you mean that if i use rjs update,i can manage it? but how ? how to
keep
the ajax and redirect to exist for the filter?

If you use rjs you can just do page.redirect_to(…) but as I said
that won’t work with your existing setup because your ajax request is
expecting html back, not javascript.

Fred