Change recorded variables created_at property

Is there a way to change a database records "created_at" variable after it created?

-------------Problems Reply------------

Sure, since rails 2.3 you can change it like any other column: get the object from the database, set the value for the column, save it.

my_model = MyModel.find(42)
my_model.created_at =

If you want to store a creation date, you may not want to use the default timestamp behavior.

Use a before_save filter, and a custom field 'creation_date'

class MyModel
before_save :set_creation_date

def set_creation_date
self.creation_date ||=

That way, if you set creation_date yourself, it will get saved to the db with that value, but otherwise will.

Category:ruby on rails Views:0 Time:2011-02-25

Related post

  • What is the different between Instance variable vs property ? 2010-11-28

    I've seen a lot of codes that do this: @interface Test0 : NSObject { @private int iVar; } @property (readwrite,assign) int iVar; @end and some other codes: @interface Test0 : NSObject { } @property (readwrite,assign) int iVar; @end I know that you us

  • Variable Object Property Names in As3 flex? 2010-12-03

    I need to create variable object property names for use with the data grid component. This works: data = new Object(); data.some_name = "the data"; But this does not: data = new Object(); colName = "some_name"; data[colName] = "the data"; Can anyone

  • Can't I set a variable at property url mx:HTTPService? 2011-08-10

    I build an application that need httpservice feature. This application will be deployed at some computer. So, I don't have an idea to set variable at url property. <mx:HTTPService id="personRequest" url="

  • Why should I use protected variables(members/property) with Inheritance? What are the advantages of using it? 2011-10-03

    I was going through code samples of Begining C# 3.0 and followed the sample code along. When I have created a public/protected method then I was able to access that method using the object of derived class. Ex: class clsBuilding { protected string ad

  • OLAP Drill Through Maximum number of records to retrieve property for Excel 2003 2014-10-26

    By default, an OLAP drill into details drill through will retrieve the first 1000 records. We are looking the option to change this limitation within Excel 2003. It is available in Excel 2007 as: Drill Through This action queries the cube based on a

  • C#: Struct returning variable without property 2009-12-15

    What I'd like to be able to do is have a struct return a variable without having to specify it by it's property. I'm probably phrasing this question incorrectly so I'll give an example (this fails of course). Apologies for any confusion or inconsista

  • create object using variables for property name 2010-06-30

    Is it at all possible to use variable names in object literal properties for object creation? Example function createJSON (propertyName){ return { propertyName : "Value"}; } var myObject = createJSON("myProperty"); console.log(myObject.popertyName);

  • Is there a way to list records by created_at DESC but only for current and past dates? 2010-12-08

    I have a Ruby on Rails application that allows for users to create a Box (gym) and then create Workouts so that users can see what they will be doing that day. Box has_many :workouts Workout belongs_to :box I have given the user the ability to edit t

  • JavaScript - creating object and using variable for property name? 2011-01-14

    This question already has an answer here: How do I add a property to a Javascript Object using a variable as the name? 2 answers I am creating my own object: gridObject = new Object(); I'm then using jquery to pull the contents of list item tags, whi

  • Why should we declare variables for @property 2011-01-16

    I am newbie in Objective. As I read many tutorial, @property has a variable for a type, the same variable is declared in @inferface too. Is this needed? Example @interface MyInterface : NSObject { NSInteger myVaribale; } @property(retain) NSInteger m

  • diff between variable and property? 2011-02-17

    Possible Duplicate: What is the difference between a field and a property in C#? i would like to know the difference between a variable and a property.can any one explain --------------Solutions------------- Simply you can't validate the data being s

  • Javascript variable as property setting for jwplayer 2011-05-18

    HELP!! i need to use a variable for the property "file" but cant find any documentation on the proper syntax. if i have: var video="**URL TO MY VIDEO**"; then i need something like this: jwplayer("movieContainer").setup({ autostart: true, flashplayer

  • Ruby on Rails, create an instance variable from another instance variable's property 2011-06-20

    I think this is an easy question but I can't seem to wrap my head around it to solve it. I want to create an instance variable from a property of another instance variable. For example: @posts = Post.find(:all, :conditions => ['day > ?', Date.t

  • PHP Class $_SERVER Variable a Property 2011-08-08

    I'm developing a class and I have this structure: class userInfo { public $interval = 60; public $av_langs = null; public $ui_ip = $_SERVER['REMOTE_ADDR']; public $ui_user_agent = $_SERVER['HTTP_USER_AGENT']; public $ui_lang = null; public $ui_countr

  • Use variable for property name in JavaScript literal? 2011-10-03

    I am new to JavaScript and trying to do some experiment with it. I have one question. I know we can create new properties in Javascript objects during runtime but would that property can be assigned a value too. For example. var value = "New value";

  • IOS : Releasing variable with @property (nonatomic, retain) 2011-10-07

    Should the Variables with the @property nonatomic and retain be released explicitly. @interface MyScreenViewController : UIViewController <UIWebViewDelegate> { UIWebView* greetingView; } @property(nonatomic, retain) IBOutlet UIWebView* greeting

  • Delphi: Undefined record variable 2011-12-12

    I have defined a TCGTable record type with the following structure: type TCGTable = record x : array [1 .. MAX_POINTS] of Single; y : array [1 .. MAX_POINTS] of Single; end; I have declared a TCGTable variable CGTable. The variable CGTable is assigne

  • Difference between private instance variable and property in class extension (Objective-c 2.0) 2011-12-22

    What are the differences (if any) between the following Objective-c 2.0 code snippets: // in MyClass.h @interface MyClass @private NSString *myString; @end and // in MyClass.m @interface MyClass () @property (nonatomic, copy) NSString *myString; @end

  • Storing variables in property list files Cocos2d 2012-01-27

    I am programming a cocos2d game where, in most games, you must complete the level previous to proceed on to the next level. Each level is in a different layer (node). I wanted to store integers (1-20) to the property list so the variables are retaine

Copyright (C), All Rights Reserved.

processed in 0.181 (s). 11 q(s)