Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes user creation with two fixes #122

Open
wants to merge 1 commit into from

1 participant

@bnickel
  1. Validation occurs before before_create. To ensure create_user is called, it has to be done on before_validation.
  2. create_user threw an error because User.new wasn't assigned to anything. After that, user.save would set self.user to true.
@bnickel bnickel Fixes user creation with two fixes:
 1. Validation occurs before `before_create`.  To ensure `create_user` is called, it has to be done on `before_validation`.
 2. `create_user` threw an error because `User.new` wasn't assigned to anything. After that, `user.save` would set `self.user` to `true`.
6c18e74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 22, 2012
  1. @bnickel

    Fixes user creation with two fixes:

    bnickel authored
     1. Validation occurs before `before_create`.  To ensure `create_user` is called, it has to be done on `before_validation`.
     2. `create_user` threw an error because `User.new` wasn't assigned to anything. After that, `user.save` would set `self.user` to `true`.
This page is out of date. Refresh to see the latest.
View
2  lib/generators/active_record/oauth_consumer_templates/consumer_token.rb
@@ -3,7 +3,7 @@ class ConsumerToken < ActiveRecord::Base
include Oauth::Models::Consumers::Token
# You can safely remove this callback if you don't allow login from any of your services
- before_create :create_user
+ before_validation :create_user_if_create
# Modify this with class_name etc to match your application
belongs_to :user
View
7 lib/oauth/models/consumers/token.rb
@@ -81,11 +81,16 @@ def params_for_user
def create_user
self.user ||= begin
- User.new params_for_user
+ user = User.new params_for_user
user.save(:validate=>false)
+ user
end
end
+ def create_user_if_create
+ create_user if id.nil?
+ end
+
end
end
end
Something went wrong with that request. Please try again.