title: Rails: retrieving image from Facebook after Omniauth login with Devise
body: <p>I setup Facebook login with Devise and omniauth with these instructions <a href="https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview" rel="noreferrer">https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview</a></p>
  
  <p>The Devise wiki gives some instructions for getting facebook info from the hash stored in this variable <code>request.env['omniauth.auth']</code> See bottom for the hash.</p>
  
  <p>For example, Devise wiki has these two methods for the <code>User.rb</code> model</p>
  
  <pre><code>def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
    data = access_token.extra.raw_info
    if user = User.where(:email =&gt; data.email).first
      user
    else # Create a user with a stub password. 
      User.create!(:email =&gt; data.email, :password =&gt; Devise.friendly_token[0,20]) 
    end
  end
  
  def self.new_with_session(params, session)
      super.tap do |user|
        if data = session["devise.facebook_data"] &amp;&amp; session["devise.facebook_data"]["extra"]["raw_info"]
          user.email = data["email"]
  
        end
      end
    end
  </code></pre>
  
  <p>So, using the hash below, I added the following to those two methods to get the name and image </p>
  
  <pre><code>def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
    data = access_token.extra.raw_info
    if user = User.where(:email =&gt; data.email).first
      user
    else # Create a user with a stub password. 
      User.create!(:email =&gt; data.email, :password =&gt; Devise.friendly_token[0,20], :name =&gt; data.name, :image =&gt; access_token.info.image) #I added access_token.info.image based on first answer
    end
  end
  
  def self.new_with_session(params, session)
      super.tap do |user|
        if data = session["devise.facebook_data"] &amp;&amp; session["devise.facebook_data"]["extra"]["raw_info"]
          user.email = data["email"]
          user.name = data["name"]
          user.image = access_token.info.image  #i changed this based on first answer below
  
        end
      end
    end
  </code></pre>
  
  <p>Then in my view, I added the following to show the user name and image</p>
  
  <pre><code>&lt;p&gt;Name:&lt;%= user.name %&gt;&lt;/p&gt;
   &lt;p&gt;Image: &lt;%= image_tag user.image %&gt;
  </code></pre>
  
  <p>However, only the name is showing. No image. </p>
  
  <p>In my database, I have a <code>name</code> and an <code>image</code> column. The name from Facebook is being stored, but the image column says 'nil'</p>
  
  <p>Any ideas how I can get the image to work? </p>
  
  <p><strong>Hash stored in</strong> <code>request.env['omniauth.auth']</code> <a href="https://github.com/mkdynamic/omniauth-facebook/blob/master/lib/omniauth/strategies/facebook.rb#L31-47" rel="noreferrer">https://github.com/mkdynamic/omniauth-facebook/blob/master/lib/omniauth/strategies/facebook.rb#L31-47</a></p>
  
  <pre><code>   info do
          prune!({
            'nickname' =&gt; raw_info['username'],
            'email' =&gt; raw_info['email'],
            'name' =&gt; raw_info['name'],
            'first_name' =&gt; raw_info['first_name'],
            'last_name' =&gt; raw_info['last_name'],
            'image' =&gt; "#{options[:secure_image_url] ? 'https' : 'http'}://graph.facebook.com/#{uid}/picture?type=square",
            'description' =&gt; raw_info['bio'],
            'urls' =&gt; {
              'Facebook' =&gt; raw_info['link'],
              'Website' =&gt; raw_info['website']
            },
            'location' =&gt; (raw_info['location'] || {})['name'],
            'verified' =&gt; raw_info['verified']
          })
        end
  </code></pre>