2008-09-26 93 views
0

我正在使用form_remote_for()对表单的数据进行验证,以便我的rails应用程序可以在不重新加载页面的情况下显示用户错误。如果没有错误,我有麻烦重定向页面。这是我的代码:如何使用form_remote_for()成功验证后重定向页面?

def create 
    # Validate the data 
    if error_count > 0 
    render :update do |page| 
     page.replace_html(div_id, error_text) 
    end 
    else 
    # Save the data 
    redirect_to(page_to_go_to) 
    end 
end 

此方法中的所有内容都可以正常工作,但重定向除外。服务器声称它做了一个成功的重定向,我相信这是重定向的AJAX调用。我想要发生的是包含要重定向的表单的页面。那可能吗?

回答

4

我想到了这一点,并意识到我需要页面重定向,而不是我正在处理的请求。所以我尝试了以下方法,效果很好。

def create 
    # Validate the data 
    if error_count > 0 
    render :update do |page| 
     page.replace_html(div_id, error_text) 
    end 
    else 
    # Save the data 
    render :update do |page| 
     page.redirect_to(page_to_go_to) 
    end 
    end 
end 
相关问题