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 8902759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:41:42+00:00 2026-06-15T01:41:42+00:00

I have a model defined in a gem (Google::APIClient.new) and I’ve created an instance

  • 0

I have a model defined in a gem (Google::APIClient.new) and I’ve created an instance of that gem in my controller.

I want to share the instance across controller actions per each user so I need to persist it somehow. I’ve tried storing it in a sessions variable (session[:client] = Google::APIClient.new) and into a field of one my own models (User.goog_client = Google::APIClient.new) which didn’t work. Is there a proper way of persisting a model from another gem per each user?

Thanks in advance!

Soln: Found a simpler soln, store the attributes in sessions then reload them into the model:

    session[:access_token] = client.authorization.access_token
    session[:refresh_token] = client.authorization.refresh_token
    session[:expires_in] = client.authorization.expires_in
    session[:issued_at] = client.authorization.issued_at

    client.authorization.access_token = session[:access_token] 
    client.authorization.refresh_token = session[:refresh_token]
    client.authorization.expires_in = session[:expires_in]
    client.authorization.issued_at = session[:issued_at]
  • 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-15T01:41:43+00:00Added an answer on June 15, 2026 at 1:41 am

    It sounds like you might want to create a wrapper class for these objects that inherits from ActiveRecord::Base.

    The attributes on your wrapper object would be whatever information is required to instantiate the object via the gem. Then you would create (or override) a finder method that does so.

    class FooWrapper < ActiveRecord::Base
    
      attr_accessible :x, :y, :z
    
      def self.get_real_foo(wrapper_id)
        wrapper_obj = self.find(wrapper_id)
        return FooGem.new(wrapper_obj.x, wrapper_obj.y, wrapper_obj.z)
      end
    end
    

    You say you tried storing the object in the session and your models? How exactly did you go about that? This may not really be the best way to solve your problem… If you post more specifics we will be better able to help you down the right path.

    Edit Addition:

    If you want the gem instance to be tied to a specific user then make FooWrapper :belongs_to :user. When you instantiate the real gem instance then you use whatever user-specific information as needed.

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

Sidebar

Related Questions

I have a UserProfile model defined in settings.py . Now I want to create
I have a model defined this way class Lga < ActiveRecord::Base validates_uniqueness_of :code validates_presence_of
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
Let's say i have a Model defined as: Foo {Id, Date} . Is there
All, i have the following model defined, class header(models.Model): title = models.CharField(max_length = 255)
Say I have a model object 'Person' defined, which has a field called 'Name'.
Lets say I have model inheritance set up in the way defined below. class
So I have a self-joining model defined. Basically a post on a forum, and
I have a Model which has some constants defined, like below: class Order(models.Model): WAITING
Suppose I have got a model ArticleVersion in my project which is defined as:

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.