相关疑难解决方法(0)

用设计手动设置return_to

我目前正在使用Devise在我的应用上验证用户身份.它在最重要的时候效果很好,但是我遇到了一个特定的操作问题:

视图:

<p id="save"><%= link_to "Save", new_save_path, :remote => true %></p>
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

如您所见,因为动作是ajax,我不能使用传统before_filter :authenticate_user!方法.因此,我将用户重定向到登录页面.

问题是,我想在用户登录时自动将用户重定向回上一页.

我知道我可以这样做,session[:"user.return_to"]但我在设置它时遇到了麻烦.我怎样才能做到这一点?或者我这样做是错的?

authentication session ruby-on-rails devise ruby-on-rails-3

5
推荐指数
1
解决办法
3065
查看次数