Thursday 15 April 2010

ruby on rails - Manually instantiating devise user models -



ruby on rails - Manually instantiating devise user models -

this question related 1 asked couple years ago:

instantiating devise user models manually using contents of params hash

i not sure if rails 4 issue, finding cannot manually instantiate devise user in controller code. used work in rails 3.

class registrationscontroller < devise::registrationscontroller ... def schema_test @user = user.new(:email => 'jhw@ausd.k12.edu', :password => 'asdf123', :password_confirmation => 'asdf123') @user.save end ... end

this devise-specific part of routes.rb: devise_for :users, :controllers => {:registrations => "registrations"}

devise_scope :user '/schema_test', to: 'registrations#schema_test' end

when phone call schema_test, finding user object not getting saved database. have suggestions?

best practice check behavior in rails console before integrate rails application.

the simplest way figure out issue read error messages devise returns. caused not meeting password requirements and/or email exists in database.

from root of application, run rails c.

@user = user.new(:email => 'jhw@ausd.k12.edu', :password => 'asdf123', :password_confirmation => 'asdf123') # check if user object valid @user.valid? # if comes false, read error messages @user.errors.messages => {:password=>["is short (minimum 8 characters)"]}

in example, user not beingness saved because password short.

ruby-on-rails devise

No comments:

Post a Comment