Rails doesn't generate created_at for fixture

后端 未结 2 1716
挽巷
挽巷 2020-12-21 04:19

I have a model Question with \"question_id\", \"elapsed_time\", \"allowed_time\" and \"status\" as its fields and a controller named Reporting that receive JSON containing q

相关标签:
2条回答
  • 2020-12-21 04:48

    My model's name was in plural form. Change it to singular and rails will generate timestamp.

    See how rails generate timestamp : https://github.com/rails/rails/blob/master/activerecord/lib/active_record/fixtures.rb#L560

    0 讨论(0)
  • 2020-12-21 05:07

    As explained in https://stackoverflow.com/a/4350202/978525 you can add something like the following to your fixture objects:

    objectA:
      foo: something
      created_at: <%= 5.day.ago.to_s(:db) %>
      updated_at: <%= 5.day.ago.to_s(:db) %>
    
    0 讨论(0)
提交回复
热议问题