undefined method `new_with_session'

1,214 views
Skip to first unread message

Christian Fazzini

unread,
Sep 27, 2010, 12:36:36 PM9/27/10
to Devise
Too many surprise errors with Devise on Rails 3, to the point where it
is starting to feel frustrating. In Rails 2.3.8, Devise had no issues
at all!

When I try to browse to the sign-up form, I get:

NoMethodError in RegistrationsController#new
undefined method `new_with_session' for #<Class:0x000001078b0148>

Which I believe i the same error from: http://old.nabble.com/devise-issue-td29754464.html

I copied over the Registrations controller and from
http://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb

and put it in app/controllers. The problem seems to be at the
following lines:

def new
build_resource({})
render_with_scope :new
end

If I comment build_resource({}) and render_with_scope :new, the form
loads without any errors. But if I try to submit, then the same error
comes back.

Any advice is much appreciated

Christian Fazzini

unread,
Sep 27, 2010, 12:40:53 PM9/27/10
to Devise
FYI, in routes.rb I've got:

devise_for :users, :controllers => { :registrations =>
'registrations' }

On Sep 28, 12:36 am, Christian Fazzini <christian.fazz...@gmail.com>
wrote:
> Too many surprise errors with Devise on Rails 3, to the point where it
> is starting to feel frustrating. In Rails 2.3.8, Devise had no issues
> at all!
>
> When I try to browse to the sign-up form, I get:
>
> NoMethodError in RegistrationsController#new
> undefined method `new_with_session' for #<Class:0x000001078b0148>
>
> Which I believe i the same error from:http://old.nabble.com/devise-issue-td29754464.html
>
> I copied over the Registrations controller and fromhttp://github.com/plataformatec/devise/blob/master/app/controllers/de...

Gonzalo Rodríguez-Baltanás Díaz

unread,
Sep 27, 2010, 12:43:12 PM9/27/10
to plataforma...@googlegroups.com

What happens if you put the controller inside a folder named "users"?

so that it is:

app/controllers/users/registrations

Carlos Antonio da Silva

unread,
Sep 27, 2010, 12:45:14 PM9/27/10
to plataforma...@googlegroups.com
Be sure you have the :registerable module included in your devise call. The only method it adds to your model is new_with_session.

2010/9/27 Gonzalo Rodríguez-Baltanás Díaz <sio...@gmail.com>



--
At.
Carlos A. da Silva

Carlos Antonio da Silva

unread,
Sep 27, 2010, 12:46:46 PM9/27/10
to plataforma...@googlegroups.com
Sorry I messed up, new_with_session only exists in Devise master. If you're running 1.1.2 ou 1.1.3, be sure to copy the right controller if you need so, in v1.1 branch (not master).

Christian Fazzini

unread,
Sep 27, 2010, 12:47:17 PM9/27/10
to Devise
I moved it to app/controllers/users/registrations

Renamed the controller to: class Users::RegistrationsController <
Devise::RegistrationsController

changed my routes to: devise_for :users, :controllers =>
{ :registrations => 'users/registrations' }

and still get:

NoMethodError in Users/registrationsController#new
undefined method `new_with_session' for #<Class:0x00000104088298>

On Sep 28, 12:43 am, Gonzalo Rodríguez-Baltanás Díaz

Christian Fazzini

unread,
Sep 27, 2010, 12:50:59 PM9/27/10
to Devise
Carlos, I already have the following in my user model:


devise :registerable, :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable,
:confirmable, :encryptor => :bcrypt#, :oauthable

Is that what you mean? or should I also have t.registrable in my user
migration file?

On Sep 28, 12:45 am, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> Be sure you have the :registerable module included in your devise call. The
> only method it adds to your model is new_with_session.
>
> 2010/9/27 Gonzalo Rodríguez-Baltanás Díaz <siot...@gmail.com>

Christian Fazzini

unread,
Sep 27, 2010, 12:56:56 PM9/27/10
to Devise
Carlos:

bundle show devise
/Users/Chris/.rvm/gems/ruby-1.9.2-p0/gems/devise-1.1.2

So this means my app is using the 1.1 branch. But, seems like it has
the same code for the registrations controller:

http://github.com/plataformatec/devise/blob/v1.1/app/controllers/devise/registrations_controller.rb

Hence why I still get the same error

On Sep 28, 12:46 am, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> Sorry I messed up, new_with_session only exists in Devise master. If you're
> running 1.1.2 ou 1.1.3, be sure to copy the right controller if you need so,
> in v1.1 branch (not master).
>
> On Mon, Sep 27, 2010 at 1:45 PM, Carlos Antonio da Silva <
>
>
>
> carlosantoniodasi...@gmail.com> wrote:
> > Be sure you have the :registerable module included in your devise call. The
> > only method it adds to your model is new_with_session.
>
> > 2010/9/27 Gonzalo Rodríguez-Baltanás Díaz <siot...@gmail.com>

Carlos Antonio da Silva

unread,
Sep 27, 2010, 12:59:08 PM9/27/10
to plataforma...@googlegroups.com
No, there is no migration related to registerable. And the link you've sent before showed you copied RegistrationsController from master, which has this: http://github.com/plataformatec/devise/blob/master/app/controllers/devise/registrations_controller.rb#L65

The call to new_with_session.

Christian Fazzini

unread,
Sep 27, 2010, 1:01:33 PM9/27/10
to Devise
Ok I copied the code from the tag 1.1.2, restarted the server, and
seems to work now. Thanks for pointing this out

On Sep 28, 12:46 am, Carlos Antonio da Silva
<carlosantoniodasi...@gmail.com> wrote:
> Sorry I messed up, new_with_session only exists in Devise master. If you're
> running 1.1.2 ou 1.1.3, be sure to copy the right controller if you need so,
> in v1.1 branch (not master).
>
> On Mon, Sep 27, 2010 at 1:45 PM, Carlos Antonio da Silva <
>
>
>
> carlosantoniodasi...@gmail.com> wrote:
> > Be sure you have the :registerable module included in your devise call. The
> > only method it adds to your model is new_with_session.
>
> > 2010/9/27 Gonzalo Rodríguez-Baltanás Díaz <siot...@gmail.com>

Carlos Antonio da Silva

unread,
Sep 27, 2010, 1:03:22 PM9/27/10
to plataforma...@googlegroups.com
No problem. Good to know it's working
Reply all
Reply to author
Forward
0 new messages