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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:50:20+00:00 2026-06-09T05:50:20+00:00

I have the following model ( sort_timestamp is a datetime): class Post < ActiveRecord::Base

  • 0

I have the following model (sort_timestamp is a datetime):

class Post < ActiveRecord::Base
  [snip attr_accessible]
  acts_as_nested_set
  after_create :set_sort_timestamp

  private
  def set_sort_timestamp
    self.sort_timestamp = self.created_at
  end
end

I’m using https://github.com/collectiveidea/awesome_nested_set . This code doesn’t set sort_timestamp. What am I doing wrong?

  • 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-09T05:50:21+00:00Added an answer on June 9, 2026 at 5:50 am

    Unless I’m missing the point of what you’re doing here, you’re probably looking for before_create if you’d like it to save when the row is created. Otherwise you’ll have to add self.save to the method, but that will cause extra database calls, so before_create might be the better option.

    (Basically, the flow of what you were doing before was that the model would be created, saved to the database, and then the object would modify its attribute sort_timestamp to be created_at; this is after your database commit, and only performed in memory (so not persisted, unless you were persisting it in another way later in the code).

    EDIT: Actually, this probably won’t work because created_at probably won’t be set before the record is created. A few options:

    1) Add self.save to end of your method with after_create
    2) Use Time.now if the times sort_timestamp and created_at don’t have to be exactly the same.
    or, 3) Try adding default value to migration: How to use created_at value as default in Rails

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

Sidebar

Related Questions

I have the following two classes: class Menu < ActiveRecord::Base has_many :menu_headers accepts_nested_attributes_for :menu_headers
I have the following model: public class Contact { public Contact() { Name =
I have the following model: public class Tag { public int Id { get;
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I have the following model and instance: class Bashable(models.Model): name = models.CharField(max_length=100) >>> foo
I have the following model: class User: name = models.CharField( max_length = 200 )
I have the following model public class UserViewModel { public String CVR_Nummer { get;
In my domain model I have following Classes.A 'UserProfile' has one 'SecurityPrincipal' class SecurityPrincipal{
I have Post and Comment model. I want to achieve the following: Each time

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.