手动设置的return_to用色器件 [英] Manually setting return_to with devise

查看:107
本文介绍了手动设置的return_to用色器件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。这对大多数工作点很好,但我有一个特定操作的麻烦:

I am currently using Devise to authenticate users on my app. It's working great for the most point, but I am having trouble with a specific action:

查看:

<p id="save"><%= link_to "Save", new_save_path, :remote => true %></p>

saves_controller.rb:

saves_controller.rb:

def new
  if user_signed_in?
    @save = Save.create(:user_id => current_user.id)
    render :update do |page|
      page.replace_html "save", "Saved!"
    end
  else
    redirect_to new_user_session_path, :notice => "You need to sign in to do that."
  end
end

正如你所看到的,因为操作是Ajax的,我不能用传统的的before_filter:的authenticate_user 方法。所以不是我重定向用户在登录页。

As you can see, because the action is an ajax one, I can't use the traditional before_filter :authenticate_user! method. So instead I am redirecting the user to the sign in page.

问题是,我想,当他们登录时自动将用户重定向回previous页。

The problem is, I want to automatically redirect the user back to the previous page when they logged in.

我明白我可以用会做到这一点[:user.return_to] ,但我无法设置它。我怎样才能做到这一点?还是我要对此都错了?

I understand I can do this with the session[:"user.return_to"] but I'm having trouble setting it. How can I do this? Or am I going about this all wrong?

推荐答案

我相信会话密钥是:#{范围} _return_to ,这将是简单的:user_return_to 用户

I believe the session key is :"#{scope}_return_to, which will be simply :user_return_to for a User class.

这篇关于手动设置的return_to用色器件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆