Tag: 重定向

重定向无法正常工作

我在投票控制员中有这条线: before_filter :authenticate 因此,当我在注销时投票时,它应该使此filter失败。 我的应用程序控制器中的我的身份validation方法如下所示: def authenticate logged_in? ? true : access_denied end 所以它返回access_denied ,如下所示: def access_denied redirect_to login_path, :notice => “You must log in to perform this action.” and return false end 因此,我应该被重定向到我的登录页面,对吧? 我在routes.rb文件中有这个: match ‘/login’ => “sessions#new”, :as => “login” 我有一个登录表单的new视图,我应该在我投票时将其重定向到我没有登录。我的投票控制器的create方法中也有这个代码: if @vote.save respond_to do |format| format.html { redirect_to @video } format.js end […]

是否有可能在Rails中检查是否已经发布了重定向或渲染?

Ruby 2.0.2,Rails 4.0.3,Sorcery 0.8.5 我试图在我的代码中发出重定向,只是为了接收已经发出重定向或渲染的错误消息。 如果是这样的话,我很高兴回来。 但是,如果由于任何其他原因调用该方法,我想检查是否已发出重定向或渲染,如果没有,则发出它。 代码是基于Sorcery的身份validation。 在应用程序控制器中,我有: def not_authenticated redirect_to login_url # , :alert => “First log in to view this page.” end 这最终检查current_user,如下所示: def current_user @current_user ||= @view.current_user unless @view.blank? begin @current_user ||= Associate.find(session[:user_id]) unless session[:user_id].blank? rescue ActiveRecord::RecordNotFound => e return end current_user = @current_user end 在救援中,我想确定是否已经发生重定向或渲染,以便我可以重定向到login_url,如果没有。 当然,这意味着它是从一种不同的方法调用的。 谢谢。

如何在使用Ruby重定向后获取最终的URL?

如果http://foo.com重定向到1.2.3.4然后重定向到http://finalurl.com ,我如何使用Ruby找到登陆URL“http://finalurl.com”?