Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8005029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:06:06+00:00 2026-06-04T17:06:06+00:00

I am using devise omniauth in my rails application, here is the User class

  • 0

I am using devise omniauth in my rails application, here is the User class

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable

  attr_accessible :email, :password, :password_confirmation, :remember_me, :encrypted_password, :fb_id

  def set_facebook_info(info)
    @facebook_info = info
  end

  def get_facebook_info
    @facebook_info
  end

  def self.find_for_facebook_oauth(access_token, signed_in_resource=nil)
    data = access_token.extra.raw_info
    if user = User.find_by_email(data.email)
      if not user.fb_id
        user.fb_id = access_token.uid
        user.save
      end
      user.set_facebook_info "whatever" <-- I tried here

      user
    else # Create a user with a stub password.
      user = User.create(:email => data.email, :password => Devise.friendly_token[0,20], :fb_id => access_token.uid)
      user
    end
  end

  def self.new_with_session(params, session)
    super.tap do |user|
          user.set_facebook_info "whatever" # <-- I Tried here too 
      if data = session["devise.facebook_data"] && session["devise.facebook_data"]["extra"]["user_hash"]
        user.email = data["email"]
      end
    end
  end
end

I want to use set and get methods for keeping some facebook user information. but when I use current_user in view, it gives me no value of what I’ve set in my User class.
like in application.html.erb :

<span><%= current_user.get_facebook_info %></span> 

returns an empty value

Does anybody has an idea about it ? It should be a common case. in general , how can we assign some non connected to DB attribute to current_user via devise ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:06:07+00:00Added an answer on June 4, 2026 at 5:06 pm

    Your @facebook_info attribute is only stored in memory, not persisted to the database. So on the next page load, Devise is going to load your model from the database again, and that is why the information is missing.

    If you want to keep the Facebook info, you need to persist it to the database. Rails has some nice ways of storing hashes directly in a text column:

    class User < ActiveRecord::Base
      serialize :preferences
    end
    
    user = User.create(:preferences => { "background" => "black", "display" => large })
    User.find(user.id).preferences # => { "background" => "black", "display" => large }
    

    Source: http://api.rubyonrails.org/classes/ActiveRecord/Base.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a web app running on Rails, using Devise and OmniAuth for user
I have a class User in Rails using Mongoid and Devise. I can't seem
I'm building a Rails application using Devise. Devise is all set up even omniauth.
So I am using Devise for user authentication in my rails app. I have
I am using Devise to manage authentication in a Rails 3.1 application. It works
I'm using cucumber to test my rails 3.1 application and i'm using devise for
I have a rails application, and I authenticate users to the application using Devise.
I'm using Rails, Devise, and Omniauth, and I'm trying to login using facebook connect.
I have a Rails 3 application using Devise for authentication. In addition to the
I am using Devise and omniauth for authentication in my rails app. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.