2017-02-22 102 views
0

當使用Rails 3.2,設計3.5.1,SimpleForm設計內嵌錯誤停止顯示覆蓋更新方法

我使用在設計自定義更新方法:

def update 
    resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key) 
    resource_updated = update_resource(resource, account_update_params) 
    if resource_updated 
     sign_in resource_name, resource, :bypass => true 
     redirect_to edit_member_registration_path, notice: "Updated successfully" 
    else 
     clean_up_passwords(resource) 
     redirect_to edit_member_registration_path, alert: resource.errors.full_messages 
    end 
end 

這是我的表單代碼:

<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 
    <%= f.error_notification %> 
    <%= f.input :first_name %> 
    <%= f.input :last_name %> 
<% end %> 

一切工作正常,但是當有驗證錯誤,我想不通爲什麼他們只顯示了在Flash消息並沒有在線。

enter image description here


當我刪除自定義更新功能,我得到這個行爲,這正是我想要的:


enter image description here

是不是有什麼毛病我更新功能?

回答

1

當你重定向,可能是resource正在裝載,並得到一個乾淨errors 而是重定向,嘗試

if resource_updated 
    sign_in resource_name, resource, :bypass => true 
    redirect_to edit_member_registration_path, notice: "Updated successfully" 
else 
    clean_up_passwords(resource) 
    respond_with resource 
end 

響應者應給予相應的提示信息,並讓資源對象中沒有任何與errors屬性,必要simple_form請注意,有一些錯誤

+0

好吧,這是有道理的,任何想法如何我可以讓它重定向到自定義路徑? –

+0

您是否嘗試過'respond_with'?我認爲它會渲染具有錯誤資源的原始頁面。如果沒有,你可以使用'render'而不是'redirect_to' – cefigueiredo