导轨,在设计sign_in stored_location重定向中保留锚标签



这里很好地描述了问题

提取:

Given我正在使用具有 Devise 身份验证的 Rails 应用程序

And我已注册

But我现在没有登录

When我访问路径"/路径#事物">

Then我应该看到登录表单

When登录

Then我应该被重定向到"/path#thing">

在您的登录页面中添加一个隐藏的输入,对我来说它是app/views/devise/sessions/new.html.haml

还有一些JavaScript来填充输入:

我调用了输入tab_hash

= simple_form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f|
= f.input :login, :hint => true, :required => true
= f.input :password, :as => :password, :hint => false, :required => true
= f.input :tab_hash, :as => :hidden
%div.text-right
= f.button :submit, t("formtastic.actions.sign_in"), class: 'btn-primary'
.text-center
%p
= render :partial => "devise/shared/links"
:javascript
$(document).ready( function(){
$("#user_tab_hash").val(window.location.hash);
});

attr_accessor :tab_hash添加到用户模型

在应用程序/控制器/application_controller.rb 中

def after_sign_in_path_for(resource)
stored = stored_location_for(resource)
if stored.present?
stored += params['user']['tab_hash'] # refs #3485 after signing in the tab was lost
end
stored || root_url
end

最新更新