设计内嵌错误停止显示覆盖更新方法
问题描述:
当使用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消息并没有在线。
当我删除自定义更新功能,我得到这个行为,这正是我想要的:
是不是有什么毛病我更新功能?
答
当你重定向,可能是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请注意,有一些错误
好吧,这是有道理的,任何想法如何我可以让它重定向到自定义路径? –
您是否尝试过'respond_with'?我认为它会渲染具有错误资源的原始页面。如果没有,你可以使用'render'而不是'redirect_to' – cefigueiredo