【发布时间】:2014-10-20 11:26:32
【问题描述】:
当用户更新失败时,我需要刷新页面。我发现的问题是我不知道如何在页面刷新时向 url 添加片段。下面的代码来自我的 Registrations 控制器,基于 Devise gem。
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)
if resource.update_with_password(account_update_params)
# If the update went well
if is_navigational_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
# What's crazy is this works
respond_with resource, location: edit_user_registration_path(anchor: params["tab_selected"])
else
# If the update goes horribly wrong
clean_up_passwords resource
# this is where the problem occurs below
respond_with resource, location: edit_user_registration_path(anchor: params["tab_selected"])
end
end
如您所见,我认为添加位置选项可以解决此问题,但我的 url 仍然返回为 coolsite.com/users,而它应该返回为 coolsite.com/users/#profile。我的问题是如何将片段设置为 URL?
【问题讨论】:
标签: ruby-on-rails url devise routing