5

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!

Community
  • 1
  • 1
Ben Orozco
  • 4,361
  • 4
  • 33
  • 49
  • Can you tell us the path of the RegistrationsController that you wrote? Also, when you run `rake routes | grep registrations` does the output look right? – andrewmitchell May 10 '11 at 23:14
  • The path is actually app/controllers/registrations_controller.rb . And the routes seem fine: http://pastebin.com/qnqaVLEt – Ben Orozco May 11 '11 at 04:16

1 Answers1

5

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.

Micah Alcorn
  • 2,363
  • 2
  • 22
  • 45
  • 1
    Nop, I'm not managing it under a sub-module, I'm following Devise classic installation instructions. – Ben Orozco May 11 '11 at 04:12
  • But, it calls directly the create method from Devise controller, doesn't seem to call the override method :( – Ben Orozco May 11 '11 at 05:22
  • In my experience, the convention for customizing the controllers is to `rails g controller Users::Registrations` which places the file in app/controllers/users/. I don't know enough about devise to know why that might be necessary. – Micah Alcorn May 11 '11 at 14:39
  • I'm using Devise 1.0.11 and Rails 2.3.10, and even that way, it just ignores the overriden method – Ben Orozco May 11 '11 at 17:30
  • Wow, that's bad news. Rails 3 migration is planned but it would requiere much time, we wanted to stick to 2.3 as long as we could. – Ben Orozco May 11 '11 at 18:55