Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise: Overriding create action in Registrations Controller for Recaptcha

I'm trying to override the create method from the Registrations Controller in Devise to include Recaptcha verification (as seen here and here):

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

Also changed my routes.rb accordingly:

  map.devise_for :users, :controllers => {:registrations => "registrations"}, :path_names => {
    :sign_up => 'signup',
    :sign_in => 'login',
    :sign_out => 'logout'
  }

When trying to visit the new registration page (with new path name: http://localhost:3000/users/signup) this errors shows up:

LoadError in RegistrationsController#new

Expected /home/benoror/project/app/controllers/registrations_controller.rb to define RegistrationsController

FULL ERROR TRACE

Any help appreciated.

BTW, I'm using Devise 1.0.11 and Rails 2.3.10, thanks!

like image 826
Ben Orozco Avatar asked May 10 '11 22:05

Ben Orozco


1 Answers

Is your controller in a Users module? If so, you will need

class Users::RegistrationsController
and
{:registrations => "users/registrations"}

Edit: According to José Valim, custom controllers don't work prior to Devise 1.1. No reason to be developing on < Rails 3 imho. Sorry I missed that in the original post.

like image 69
Micah Alcorn Avatar answered Nov 19 '22 12:11

Micah Alcorn