在Rails 4.2.4中,我使用了Devise gem (3.5.6,3.5.2,3.2.4),并试图使其适用于特定的场景。
当用户试图通过电子邮件访问user_profile_url(:anchor=>'section1')页面时,它会要求用户登录;登录后,会进入users_home_path。如果他已经登录,那么它将重定向到user_profile_url页面(#section1)。
我想在创建会话后立即重定向到user_profile_url(:anchor=>'section1') (从电子邮件链接单击)?我试图通过修改after_sign_in_path_for(resource)方法来修复它,但它不起作用。
def after_sign_in_path_for(resource)
session[:return_to] || users_home_path
end在html视图中,
<div id="unsubscribe">
...
</div>我怎样才能让这个重定向起作用?
发布于 2016-05-30 20:45:07
您需要像下面的代码片段那样为session:return_to编写代码
def store_location
# store last url - this is needed for post-login redirect to whatever the user last visited.
return unless request.get?
if (request.path != "/users/sign_in" &&
request.path != "/users/sign_up" &&
request.path != "/users/password/new" &&
request.path != "/users/password/edit" &&
request.path != "/users/confirmation" &&
request.path != "/users/sign_out" &&
!request.xhr?) # don't store ajax calls
session[:previous_url] = request.fullpath
end
endhttps://stackoverflow.com/questions/37525412
复制相似问题