Authlogic Rails 3.1

12
人们在Rails 3.1中使用哪个版本的authlogic呢? 我在我的gemfile中有以下条目:
gem 'authlogic', :git => 'https://github.com/AndreasWurm/authlogic.git'

我遇到的问题是在我的基础ApplicationController中的一段代码。

def require_no_user
  if current_user
    store_location
    flash[:notice] = "You must be logged out to access this page"
    redirect_to :controller => "home", :action => "index"
    return false
  end
end

def store_location
  session[:return_to] = request.request_uri
end
我遇到的错误出现在这一行代码:

The error I am getting is with the line:

session[:return_to] = request.request_uri

我遇到了一个错误,提示如下:

undefined method `request_uri' for #<ActionDispatch::Request:0x7dadd4d8>

Request_uri已经从ActionDispatch中移除了吗?如果是,正确的替代方法是什么?

2个回答

30

最佳解决方案来自Vadim的建议,使用ActionDispatch::Request中的新方法:

只需将以下内容替换:

def store_location
  session[:return_to] = request.request_uri
end

作者:

def store_location
  session[:return_to] = request.url
end

完成了!


7

fullpath将给出带参数的url(但不包括协议、端口和域名),而request.url将提供fullpath跳过的所有内容。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接