简体   繁体   中英

Using Prototype, is it possible “redirect_to” avoiding to process the full “js.rjs” code?

In *user_controller.rb* file I have this code:

respond_to do |format|
    if test = true
        format.js
    else
        format.js { @yo = true }
    end
end

In update.js.rjs file I have this code

page.redirect_to :action => "index" if @yo == true
page.replace_html...
...

This is a hack to redirect a Java responce passing a variable (@yo == true). However I think is better to do something like "redirect_to" in braces avoiding to process the code in update.js.rjs :

respond_to do |format|
    if test = true
        format.js
    else
        format.js { redirect_to ... } # something example
    end
end

but I do not know how to do that or whether it is possible. Can anyone advise me on the issue?

You could use two different .js files in your respond_to block.

respond_to do |format|
    if test = true
        true.js
    else
        false.js
    end
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM