undefined method `render_with_scope’ (Devise) – Ruby on Rails

I ran into the following error while trying to implement ReCaptcha with devise:

undefined method `render_with_scope' for #<Users::RegistrationsController:0xb41fbd14>

The offending code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Users::RegistrationsController < Devise::RegistrationsController
  def create
 
    #Verify captcha
    if verify_recaptcha
      super
    else
      build_resource
      clean_up_passwords(resource)
      flash.now[:alert] = "There was an error with the recaptcha code below. Please re-enter the code."
      render_with_scope :new
    end
  end
end

This error was caused by the fact that I’d followed an out of date tutorial. Devise no longer uses render_with_scope. Thankfully the solution was pretty straight forward, simply switch render_with_scope with render:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Users::RegistrationsController < Devise::RegistrationsController
  def create
 
    #Verify captcha
    if verify_recaptcha
      super
    else
      build_resource
      clean_up_passwords(resource)
      flash.now[:alert] = "There was an error with the recaptcha code below. Please re-enter the code."
      render :new
    end
  end
end

There’s a brief explanation available at the following link: http://groups.google.com/group/plataformatec-devise/browse_thread/thread/596381554ba1fb04

Leave a Reply