0

I'm trying to create a Devise user manually. The hitch is that validations only seem to pass when I call User.create.

When I call User.new, the resulting user instance is invalid. Unfortunately, I can't determine why.

The resulting error message is simply "Validation failed: ".

Any idea what's going on?

I would prefer not to use User.create because I want to call #skip_confirmation! prior to save, so that there's no email that goes out.

Any ideas how to debug this? I've tried walking through the stack trace, but no luck.

if user = User.create(params[:user])
  user.skip_confirmation!
  user.save!
  flash[:success] = "New user #{user.email} created."
  redirect_to user_root_path
else
  flash[:alert] = user.errors
  redirect_to user_root_path
end
dsilver829
  • 295
  • 1
  • 3
  • 9
  • have you check the errors object? – Polygon Pusher Feb 16 '13 at 01:00
  • 1
    `user = User.create(params[:user])` will always be truthy unless an exception is raised. When you use `User.new(params[:user])`, what are the specific errors? Posting the params hash would help. – dwhalen Feb 16 '13 at 02:27

3 Answers3

0

try to add a password to parameters array.

params[:user][:password] = Devise.friendly_token[0,20]

Helio Santos
  • 6,606
  • 3
  • 25
  • 31
0

I can't explain why this works, but it appears that calling user.confirm! prior to calling user.skip_confirmation! resolved the issue.

dsilver829
  • 295
  • 1
  • 3
  • 9
0

Change the conditional because that value will always answer true. As dwhalen said.

Blaine Hatab
  • 1,626
  • 17
  • 24