Tag Archives: devise

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 #

The offending code:

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:

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

Advertisements

Devise Overriding Controller Route – Ruby on Rails

I ran into a bit of a problem today after implementing a search form that appeared on every page. When the login page was loaded I received the following error:

No route matches {:controller=>”devise/products”, :method=>:get, :action=>”search”}

The weird thing about this is that the route my search form uses does not mention devise in any way:

 'products', :action => 'search', :method => :get do %>

As you have probably already guessed, I’m using devise to handle my authentication. Unfortunately this seems to be overriding some of my routes whenever it co-exists with another form. Luckily there exists a very simple, although hard to find solution – simply add a forward slash before the controller definition:

 '/products', :action => 'search', :method => :get do %>

Here’s a quick link to the StackOverflow post which gave the answer, hopefully a few more links to it will make it a little easier to find for anyone else out there doing a search!