RailsCasts Pro episodes are now free!

Learn more or hide this

Aaron Thomas's Profile

GitHub User: frostsquid

Comments by Aaron Thomas

Avatar

Nevermind... I found out my issue was that in the model I was still validating the presence of several fields (including the password).

Avatar

This is great! But I am having a bit of an issue. I can not seem to get it to bypass the password as easily as it should be.

I am allowing login via facebook using the information from this railscasts. My resource is :subscriber instead of :user, but the rest is pretty much the same.

ruby
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
   def all
     subscriber = Subscriber.from_omniauth(request.env["omniauth.auth"])
     if subscriber.persisted?
       sign_in_and_redirect subscriber, notice: "Signed in!"
     else
        .....the rest of what you see in the railscasts

and my model contains:

ruby
   # populates db with information from omniauth'ed subscriber(facebook)                                         
   def self.from_omniauth(auth) 
     where(auth.slice(:provider, :uid)).first_or_create do |subscriber|                             
       subscriber.provider = auth.provider 
       subscriber.uid = auth.uid                                                                                 
       subscriber.email = auth.info.email 
       subscriber.firstname = auth.info.first_name                                            
       subscriber.lastname = auth.info.last_name 
     end 
   end   
         
   # persists subscriber information through the session 
   # when omniauth'ed subscriber (facebook)                                                                      
   def self.new_with_session(params, session) 
     if session["devise.subscriber_attributes"]                                                                  
       new(session["devise.subscriber_attributes"], without_protection: true) do |subscriber| 
         subscriber.attributes = params                                                   
         subscriber.valid? 
       end                                                                                     
     else 
       super                                                                                            
     end 
   end 
         
   def password_required?                                                                     
     super && provider.blank? 
   end 

When I run debugger and interject immediately before subscriber.persisted? I can see I have a provider and a uid for subscriber, but subscriber.persisted? returns false because subscriber.new_record? is true.

What am I missing?