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

This site uses Akismet to reduce spam. Learn how your comment data is processed.