Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在过滤器不运行之前跳过&x27;我真的不会跳过_Ruby On Rails_Ruby_Devise_Ruby On Rails 3.2 - Fatal编程技术网

Ruby on rails 在过滤器不运行之前跳过&x27;我真的不会跳过

Ruby on rails 在过滤器不运行之前跳过&x27;我真的不会跳过,ruby-on-rails,ruby,devise,ruby-on-rails-3.2,Ruby On Rails,Ruby,Devise,Ruby On Rails 3.2,所以,我有一个模型用户 class User < ActiveRecord::Base devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable attr_accessible :email, :password, :password_confirmation, :remember_me end 所以,根据日志,在

所以,我有一个模型用户

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  attr_accessible :email, :password, :password_confirmation, :remember_me
end
所以,根据日志,在过滤器不工作之前跳过。我做错了什么



编辑:我不想在有人未登录时创建用户,所以跳过:authenticate\u user!这不是我的选择。顺便说一句,Registrable在用户模型中只是临时的。

您需要将更改应用到正确的控制器,在这种情况下,
设计::RegistrationController
。简单地将其扩展如下(未经测试,但原理应该有效):


您可以在“优秀”中搜索许多扩展Desive控制器的示例。

您是否试图跳过
:authenticate\u user过滤器?正如我在下面写的:如果我跳过:验证用户!然后,没有身份验证的用户可以创建一个帐户,我不希望这样(我知道实际上在用户模型中有:registerable,但在“正常”用户创建工作完成后它将被删除)。仔细查看您的日志输出:执行控制器是
design::registationsController
,而不是
userscocontroller
。这就是为什么
skip\u before\u filter
在这种情况下无效的原因-它在错误的控制器中使用。你是对的!有没有办法从UsersController中跳过它?如果这是您唯一的更改,您可以简单地扩展Desive的控制器。我很快会补充一个答案。这对你有用吗?我正试图做完全相同的,它似乎不适合我(仍然可以创建用户时,不登录),虽然我认为它应该。。(我的问题是:)
class UsersController < ApplicationController
  before_filter :authenticate_user!

  skip_before_filter :require_no_authentication, :only => [:create]

  # ...
end
Started POST "/users" for 127.0.0.1 at 2012-12-13 22:33:34 +0100
Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"wkJ8ZxVUg9eaFiL+Guu+QIfjGiwGANReiv2bTu3YQPg=", "user"=>{"email"=>"test@test.pl", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Save"}
  User Load (0.3ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
Redirected to http://localhost:3000/
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 2ms (ActiveRecord: 0.3ms)
# app/controllers/registration_controller.rb
class RegistrationsController < Devise::RegistrationsController
  skip_before_filter :require_no_authentication, :only => [:create]
end
# routes.rb
devise_for :users, :controllers => { :registrations => "registrations" }