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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:44:31+00:00 2026-05-26T04:44:31+00:00

In Rails 2.3.6 I’m storing some serialized data in a database field. My feed_event.data

  • 0

In Rails 2.3.6 I’m storing some serialized data in a database field.

My “feed_event.data” field in my database is stored as text and is (for example) equal to:

{:post=>{:pic=>"http://s3.amazonaws.com/criticalcity/datas/3524/big_thumb/send-a-letter.jpg", :name=>"Un’istruzione perfetta", :id=>1995, :authors=>"Delilah"}, :user=>{:pic=>"http://s3.amazonaws.com/criticalcity/avatars/537/thumb/DSCN2744.JPG", :name=>"Luci!", :id=>537}}

Now I need to output this field as a string (exactly as it is in the database), but when I ask:

puts feed_event.data

outputs:

postpichttp://s3.amazonaws.com/criticalcity/datas/3524/big_thumb/send-a-letter.jpgnameUn’istruzione perfettaid1995authorsDelilahuserpichttp://s3.amazonaws.com/criticalcity/avatars/537/thumb/DSCN2744.JPGnameLuci!

Why?
How can I output it as a yaml string?

UPDATE

In order to create it I have this in my FeedEvent model:

class FeedEvent < ActiveRecord::Base
   has_many :user_feed_events, :dependent => :destroy
   has_many :users, :through => :user_feed_events

   serialize :data

 end

And in order to create a new FeedEvent element I do:

feed = FeedEvent.create(:event_type => "comment #{commentable_type}", :type_id => id, :data => {:user => {:id => user.id, :name => user.name, :pic => user.avatar.url(:thumb)}, :comment => {:id => id, :body => body, :commentable_id => commentable_id, :commentable_type => :commentable_type, :commentable_name => commentable.name}}) 

UPDATE #2

following nzifnab’s hint I used the .to_yaml method, but what Rails outputs in this case is:

data: "--- \n:post: \n  :pic: http://s3.amazonaws.com/criticalcity/datas/3524/big_thumb/send-a-letter.jpg\n  :authors: Delilah\n  :name: \"Un\\xE2\\x80\\x99istruzione perfetta\"\n  :id: 1995\n:user: \n  :pic: http://s3.amazonaws.com/criticalcity/avatars/537/thumb/DSCN2744.JPG\n  :name: Luci!\n  :id: 537\n"

Also commenting “serialize :data” in the model outputs the same.

Thanks,
Augusto

  • 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-26T04:44:31+00:00Added an answer on May 26, 2026 at 4:44 am

    When you call feed_data.data rails has automatically de-serialized your string. You could print it out like this:

    feed_data.data.inspect to get the ruby hash representation as a string, but since it’s already de-serialized it for you do you need to do anything else?

    you can call everything on it like feed_data.data[:post][:pic]

    I’m not sure what method you can use to grab the raw serialized string from the record, but usually you don’t need to.

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

Sidebar

Related Questions

Rails simulates a DELETE on a resource by using POST and a hidden field
Rails introduced some core extensions to Ruby like 3.days.from_now which returns, as you'd expect
Rails 3.2.1 app name: demo database: mongoDB with mongoid I have this scaffolding set
Rails is returning the wrong date from my database records. For my model (Target),
Rails 2.3.3 Database and Model Schema User (id,name,email) posts (id,subject,message,user_id) How can I display
Rails 3 recommend Rest. For example, I make Blog system. ### PostsController # show
Rails guides show the following example as a generic search form. <%= form_tag(search_path, :method
Rails, for example, has a defined set of patterns it uses to define ids
Rails 3.1 Nested_forms Ran into some issues setting up and might have hacked the
Rails 2.3.5 I have a form where there is a form field called 'MAX'

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.