【发布时间】:2014-05-14 07:35:56
【问题描述】:
我有一个设计附带的编辑页面。要在我的应用程序中使用它,我需要呈现一个特殊的布局,并且该布局应该只在编辑页面中呈现。 所以为了覆盖我写了编辑方法.. 这是我的registration_controller.rb
def edit
session[:tab] = "Edit Profile"
render layout: 'calculator'
end
def update
self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
p '----------------'
resource_updated = update_resource(resource, account_update_params)
yield resource if block_given?
if resource_updated
if is_flashing_format?
flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
:update_needs_confirmation : :updated
set_flash_message :notice, flash_key
end
sign_in resource_name, resource, bypass: true
respond_with resource, location: after_update_path_for(resource)
else
clean_up_passwords resource
redirect to '/users/edit'
end
end
如果我输入了错误的密码,就会发生错误并且渲染失败。 所以我想在我的更新功能中重定向到编辑网址。事情是当它重定向到编辑页面时我也想显示错误消息。
或者有什么简单的方法可以做到这一点。我想在编辑页面中呈现一个布局,当更新时发生错误时不会中断(如密码不匹配)
【问题讨论】:
-
问题可能是您使用
redirect引起的。我认为重定向调用会擦除闪存(如此处所述:stackoverflow.com/questions/7510418/…)
标签: ruby-on-rails ruby ruby-on-rails-3 devise