Ruby on rails Rails 3-筛选器链暂停为:呈现或重定向身份验证

Ruby on rails Rails 3-筛选器链暂停为:呈现或重定向身份验证,ruby-on-rails,ruby,authentication,redirect,action,Ruby On Rails,Ruby,Authentication,Redirect,Action,我仍然收到标题中的“错误”信息,不知道如何解决它。 在应用程序控制器中 class ApplicationController < ActionController::Base protect_from_forgery before_filter :mailer_set_url_options helper_method :current_user_session, :current_user def mailer_set_url_options Act

我仍然收到标题中的“错误”信息,不知道如何解决它。 在应用程序控制器中

class ApplicationController < ActionController::Base
   protect_from_forgery
   before_filter :mailer_set_url_options
   helper_method :current_user_session, :current_user

   def mailer_set_url_options
     ActionMailer::Base.default_url_options[:host] = request.host_with_port
   end

   private
      def current_user_session
        logger.debug "ApplicationController::current_user_session"
        return @current_user_session if defined?(@current_user_session)
        @current_user_session = UserSession.find
      end

      def current_user
        logger.debug "ApplicationController::current_user"
        return @current_user if defined?(@current_user)
        @current_user = current_user_session && current_user_session.user
      end

      def authentication
        logger.debug "ApplicationController::authentication"
        unless current_user
          store_location
          flash[:warning] = "You must be logged out to access this page"
          redirect_to root_url
          return false
        end
      end

      def store_location
        session[:return_to] = request.url
      end
end
以及用户控制器

class UsersController < ApplicationController
  before_filter :authentication, only: [:index, :edit, :update, :destroy, :action_a, :action_b]
  #skip_before_filter :authentication, :only => [:account_activity] didn't help as well

  def account_activity
    unless current_user.nil?
      puts 'A'
      if params[:user_id] && params[:status]
        puts 'B'
        User.find(params[:user_id]).update_attributes(:active => params[:status])
        flash[:notice] = 'Activity was successfully changed.'
      end
    end
    redirect_to :back
  end
...

我如何解决这个问题?我曾尝试在谷歌上搜索,但不幸的是,我仍然不知道如何修复它。

我只是在一个用户身上发现了这个错误

事实证明,用户有一个字段(我们最近添加了长度验证)包含的文本比允许的文本多。由于验证是新的,而且用户已经在那里了,所以错误不断地出现

我在尝试使用“!”更新其属性以明确错误时发现了它

> User.last.update_attributes!(:email => "someone@domain.com") 
用户加载(0.3ms)从
users
ORDER BY
users
id
描述限制1(0.1ms)开始用户存在(0.2ms)选择1作为一个 来自
用户
其中(
用户
电子邮件
='someone@domain.com"及
用户
id!=2020)限制1(0.1ms)回滚 ActiveRecord::RecordInvalid:验证失败:摘要太长 (最多650个字符)


因此,更改字段“Summary”的内容就解决了这个问题。

当您从过滤器之前的某个位置重定向时,过滤器链将停止。如果一切正常,您可以忽略此消息

,您需要显示更多有关发生了什么的信息,例如请求来自何处和/或错误日志。我猜“redirect_to:back”将发送到您的应用程序,以执行位于控制器顶部的before_筛选器列表中的一个操作,用于:身份验证。@rossta我将从日志更新OP添加的输出。是的,我将应用程序重定向到操作,该操作位于
before\u filter
列表中-到操作
edit
。但是到动作
编辑
时,应用程序也从动作
更新
重定向到了动作
编辑
——这很有效。此外,如果我删除重定向,然后手动设置我的应用程序的
主页url
,那么我会得到相同的错误…+1表示“!”-技巧。我对此一无所知,这导致我解决了这个问题。
Started GET "/users/account_activity?user_id=31&status=0" for 127.0.0.1 at 2012-09-28 00:40:10 +0200
Processing by UsersController#account_activity as HTML
  Parameters: {"user_id"=>"31", "status"=>"0"}
ApplicationController::current_user
ApplicationController::current_user_session
  User Load (0.7ms)  SELECT "users".* FROM "users" WHERE "users"."persistence_token" = '...' LIMIT 1
   (0.1ms)  BEGIN
   (0.7ms)  UPDATE "users" SET "last_request_at" = '2012-09-27 22:40:10.258152', "perishable_token" = '...', "updated_at" = '2012-09-27 22:40:10.259093' WHERE "users"."id" = 31
   (0.7ms)  COMMIT
ApplicationController::current_user_session
  User Load (0.4ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1  [["id", "31"]]
   (0.1ms)  BEGIN
  User Exists (0.6ms)  SELECT 1 FROM "users" WHERE ("users"."email" = 'abc@def.com' AND "users"."id" != 31) LIMIT 1
   (0.5ms)  UPDATE "users" SET "active" = 0, "perishable_token" = '...', "updated_at" = '2012-09-27 22:40:10.267227' WHERE "users"."id" = 31
   (0.7ms)  COMMIT
Redirected to http://localhost:3000/users/31/edit
Completed 302 Found in 19ms (ActiveRecord: 4.5ms)


Started GET "/users/31/edit" for 127.0.0.1 at 2012-09-28 00:40:10 +0200
Processing by UsersController#edit as HTML
  Parameters: {"id"=>"31"}
ApplicationController::authentication
ApplicationController::current_user
ApplicationController::current_user_session
  User Load (0.7ms)  SELECT "users".* FROM "users" WHERE "users"."persistence_token" = '...' LIMIT 1
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 31 LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :authentication rendered or redirected
Completed 302 Found in 5ms (ActiveRecord: 1.3ms)
> User.last.update_attributes!(:email => "someone@domain.com")