2008-09-26 37 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 
相關問題