【发布时间】:2011-02-07 16:32:09
【问题描述】:
我想将用于编辑用户及其个人资料的 url 隐藏在更安全、更有意义的 url 后面。例如,我希望/user/13/edit 成为/settings/account 和/user/13/profile/edit 成为/settings/profile。
我设法实现了这一点,但为此我必须从会话的current_user 位加载用户信息。像这样:
# users_controller
def edit
@user = current_user
end
# profiles_controller
def edit
@user = current_user
@profile = @user.profile
end
但是现在,由于我无法将来自params 的@user.id 与会话中的current_user 进行比较,我如何才能阻止旧网址(/user/13/edit 和/user/13/profile/edit)被利用?他们总是为当前用户加载表单,所以不会造成任何伤害,但如果他们只是产生 404 错误或其他什么,我会更舒服。
提前致谢。
【问题讨论】:
标签: ruby-on-rails redirect routing http-status-code-404