设计内联错误在覆盖更新方法时停止显示
Devise inline errors stop showing up when overriding update method
使用 Rails 3.2,设计 3.5.1,SimpleForm
我在 Devise 中使用自定义更新方法:
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
Responder 应该呈现适当的 flash 消息,并让资源对象保持 errors
属性不变,这是 simple_form 意识到有一些错误所必需的
使用 Rails 3.2,设计 3.5.1,SimpleForm
我在 Devise 中使用自定义更新方法:
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
Responder 应该呈现适当的 flash 消息,并让资源对象保持 errors
属性不变,这是 simple_form 意识到有一些错误所必需的