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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:55:04+00:00 2026-06-15T10:55:04+00:00

When I was creating a model, I made a column edited:timestamp. t.timestamp :edited #

  • 0

When I was creating a model, I made a column edited:timestamp.

t.timestamp :edited # in migration file

Was expecting that whenever user edits anything in this model, the time/date will be updated.

But I just saw that in database schema it is written down as

t.datetime "edited"

and it expects user to enter data in a form.

What’s happening here?

How should I change my migration file to make a timestamp column in SQL DB? Or I should assign it in the model itself?

I don’t want it to depend on user input, has to be a system cell

thx.

  • 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-15T10:55:12+00:00Added an answer on June 15, 2026 at 10:55 am

    When you create a model, you should then generate a ActiveRecord migration to create the table that will store the data associated with this model. For example, if your model is called ‘Product’, run:

    rails g migration create_products_table
    

    this will generate a migration file in db/migrate (prefixed with the timestamp at which you generated the migration file, eg: “20121201200720_create_products_table.rb”)

    The migration file should look like this:

    class CreateProducts < ActiveRecord::Migration
      def change
        create_table :products do |t|
    
          t.timestamps
        end
      end
    end
    

    When you run this migration (rake db:migrate), ActiveRecord will automatically create two columns in your table : created_at and updated_at. Then go and have a look at your schema.rb (in db). There will be something like that:

    create_table "products", :force => true do |t|
        t.datetime "created_at", :null => false
        t.datetime "updated_at", :null => false
    end
    

    created_at will store the timestamp at which the product was created.
    updated_at will store the timestamp at which the product was last updated (what you’re looking for here)

    So you don’t have to create a custom column, you should just rely on ActiveRecord’s built-in timestamps.

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

Sidebar

Related Questions

I've made a mistake of creating my own User model and am trying to
I am creating a model binder to use with asp.net mvc. This is what
I am creating a model for users and I want that property joined was
I'm creating a my own custom User model by extending the User model provided
I have one model User and will be creating another one Category . Both
I use Entity framework for creating model. I have table hierarchy where User is
I'm looking at creating map tiles based on a 3D model made in blender,
I'm looking for a free and simple tool for creating relational model diagrams. All
I am creating a Category model and using the awesome_nested_set plugin (a replacement for
I am creating the domain model in my system. When designing my model objects,

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.