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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:15:37+00:00 2026-06-06T20:15:37+00:00

In my model I have: class Log < ActiveRecord::Base serialize :data … def self.recover(table_name,

  • 0

In my model I have:

class Log < ActiveRecord::Base
serialize :data

...

def self.recover(table_name, row_id)
    d = Log.where(table_name: table_name, row_id: row_id).where("log_type != #{symbol_to_constant(:delete)}").last
    row = d.data

    raise "Nothing to recover" if d.nil?
    raise "No data to recover" if d.data.nil?

    c = const_get(table_name)
    ret = c.create(row.attributes)

end

And in my controller I calling it as:

def index
    Log.recover params[:t], params[:r]
    redirect_to request.referer
end

The problem is, if I access this page for the first time, I am getting error specified below, but after refresh, is everything OK. Where can be problem?

undefined method `attributes' for #<String:0x00000004326fc8>

In data column are saved instances of models. For the first time column isn’t properly unserialized, it’s just yaml text. But after refresh everything is fine. That’s confusing, what is wrong? Bug in rails?

It’s not every time, sometimes in first access everything is okey.

  • 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-06T20:15:40+00:00Added an answer on June 6, 2026 at 8:15 pm

    Deyamlizing an object of class Foo will do funny things if there is no class Foo. This can quite easily happen in development becauses classes are only loaded when needed and unloaded when rails thinks they might have changed.

    Depending on whether the class is loaded or not the YAML load will have different results (YAML doesn’t know about rail’s automatic loading stuff)

    One solution worth considering is to store the attributes hash rather than the activerecord object. You’ll probably avoid problems in the long run and it will be more space efficient in the long wrong – there’s a bunch of state in an activerecord object that you probably don’t care about in this case.

    If that’s not an option, your best bet is probably to make sure that the classes that the serialized column might contain are loaded – still a few calls to require_dependency 'foo' at the top of the file.

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

Sidebar

Related Questions

I have got this model: class User < ActiveRecord::Base has_and_belongs_to_many :roles before_destroy do |u|
I have a model: class EvidenceType < ActiveRecord::Base has_many :evidences attr_accessible :name end A
I have three models : class LevelTwoArea < ActiveRecord::Base has_many :places, dependent: :restrict end
Model I class TimeLog < ActiveRecord::Base has_one :custom_time_fields, :dependent => :destroy end Model II
I have class: @custom_decorator class Creature(objects): def __init__(self): pass def rise_hands(self, *args, **kwargs): print
In my business model I have Entity class (IPoint interface ) that has a
I have model public class UploadOptionModel { public UploadOptionModel() { OutputFormat = outputFormatList.Select(i =>
Suppose I have class Foo(db.Model): bar = db.ReferenceProperty(Bar) foo = Foo.all().get() Is there a
I have a class Model: class Model { ... boost::shared_ptr<Deck> _deck; boost::shared_ptr<CardStack> _stack[22]; };
I have a model class similar to the following: using System; using System.Collections.Generic; using

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.