设计:覆盖Recaptcha注册控制器中的创建操作

Ben*_*zco 5 overriding ruby-on-rails recaptcha devise

我正在尝试从Devise中的Registrations Controller覆盖create方法,以包含Recaptcha验证(如此此处所示):

class RegistrationsController < Devise::RegistrationsController

  def create
    if verify_recaptcha
      super
    else
      build_resource
      clean_up_passwords(resource)
      flash[:alert] = "Bad words."
      render_with_scope :new
    end
  end

end
Run Code Online (Sandbox Code Playgroud)

也改变了我的routes.rb:

  map.devise_for :users, :controllers => {:registrations => "registrations"}, :path_names => {
    :sign_up => 'signup',
    :sign_in => 'login',
    :sign_out => 'logout'
  }
Run Code Online (Sandbox Code Playgroud)

当尝试访问新的注册页面(使用新路径名:http:// localhost:3000/users/signup)时,会显示以下错误:

LoadError in RegistrationsController#new

Expected /home/benoror/project/app/controllers/registrations_controller.rb to define RegistrationsController
Run Code Online (Sandbox Code Playgroud)

完全错误的痕迹

任何帮助赞赏.

顺便说一下,我正在使用Devise 1.0.11和Rails 2.3.10,谢谢!

Mic*_*orn 5

您的控制器是否在用户模块中?如果是这样,你将需要

class Users::RegistrationsController

{:registrations => "users/registrations"}

编辑: 根据JoséValim的说法,自定义控制器在Devise 1.1之前不起作用.没有理由在<Rails 3 imho上开发.对不起,我在原帖中错过了.