成功登录后重定向但仍有浏览器地址栏中显示的原始URL

时间:2012-11-29 21:05:23

标签: ruby-on-rails devise

我正在使用设计开发用户身份验证。登录页面就像 本地主机:3000 /用户/ sign_in。登录成功后(Post请求),用户被重定向到主页(localhost:3000 /)。这是预期的,我确实看到主页内容在浏览器中加载。

但是,浏览器地址栏仍然将原始请求网址显示为localhost:3000 / users / sign_in

知道为什么会这样吗?是设计配置还是导轨服务器? 我这里没有太多我自己的代码,几乎只是为我的用户模型设置了默认的设计选项。

以下是我路线的一部分:

new_user_session GET  /users/sign_in(.:format)  devise/sessions#new
user_session     POST /users/sign_in(.:format)  devise/sessions#create
root                  /                         home#index

谢谢!

2 个答案:

答案 0 :(得分:1)

以下是最新设计版本的代码块

档案:../gems/devise-2.1.2/app/controllers/devise/sessions_controller.rb

# POST /resource/sign_in
def create
  resource = warden.authenticate!(auth_options)
  set_flash_message(:notice, :signed_in) if is_navigational_format?
  sign_in(resource_name, resource)
  respond_with resource, :location => after_sign_in_path_for(resource)
end

def after_sign_in_path_for(resource_or_scope)
  stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope)
end

def signed_in_root_path(resource_or_scope)
  scope = Devise::Mapping.find_scope!(resource_or_scope)
  home_path = "#{scope}_root_path"
  if respond_to?(home_path, true)
    send(home_path)
  elsif respond_to?(:root_path)
    root_path
  else
    "/"
  end
end

如果您将root配置为Home#Index,并且受before_filter :authenticate_user!保护,则在输入用户名和密码后,该url必须是您的域名。

答案 1 :(得分:0)

原来它已经......与我的jquery移动包含有关。 这个链接解决了我的问题:

rubyrails using jquery mobile, redirect not change url