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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:07:43+00:00 2026-05-27T21:07:43+00:00

I have a model and in that model I’m generating a more complex field

  • 0

I have a model and in that model I’m generating a more complex field than I’ve done before. I’ve serialized hashes and arrays, but this field is the result of Gibberish::RSA.generate_keypair ( https://github.com/mdp/gibberish ). Which is more or less a private/public key pair in a ruby wrapper, to my understanding.

Working from the command line, I can do an update_attributes and the result of the generation gets stored in the text field. When doing rake db:seed or creating an instance, this doesn’t work, I get a yaml string that indicates several types of Gibberish objects.

How do I do more complex activerecord serialization beyond hashes and arrays? Or how do I approach a greater understanding of what I’m trying to do?

Code:

  def generate_keypair
    self.update_attributes(:rsakey => Gibberish::RSA.generate_keypair(1024) )
  end

which I call on the associated model creation, basic call the Gibberish wrapper

Then the output I get for the field myresource.rsakey

"--- !ruby/object:Gibberish::RSA::KeyPair\nkey:
!ruby/object:OpenSSL::PKey::RSA {}\ncipher:
!ruby/object:OpenSSL::Cipher::Cipher {}\n"

Updating the attributes works from the rails command line, but not while seeding or creating. Other ways I attempted to add serialize so far have completely ruined the process or the created instances.

EDIT: solved bluntly by just calling ‘to_s’ on the result of the keypair generation method, which just saves it as a text field that ‘works for now’ until it needs to be more elegant.

  • 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-05-27T21:07:44+00:00Added an answer on May 27, 2026 at 9:07 pm

    The underlying issue seems to be that the openssl library doesn’t implement YAML dumping:

    YAML.dump(OpenSSL::PKey::RSA.generate(1024))
    #=> "--- !ruby/object:OpenSSL::PKey::RSA {}"
    

    If you are using rails 3.1 you can define custom serializers, like so

    class KeySerializer
      def dump(key)
        key.to_pem
      end
    
      def load(data)
        data && OpenSSL::Pkey::RSA.new(data)
      end
    end
    

    Then in your class you can do

    class Foo < ActiveRecord::Base
      serialize :key, KeySerializer.new
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that needs to have a field named complex and another
Specifically, I have a model that has a field like this pub_date = models.DateField(date
I have model classes that have as properties items of complex types (i.e., other
I have a model that contains a boolean field representing the item's approval or
I have a model that has this field on it: token = models.CharField(max_length=32, default=,
I have a model that looks like this (well not really but it has
I have a model that members will be able to update but their changes
I have a model that looks like this: @MappedSuperclass @AccessType(field) public abstract class BaseEntity
I have a model that has a bunch of attributes but the two of
I have a Model that I can bind correctly for display purposes but I

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.