Railsコンソールの出力は次のとおりです。
Loading development environment (Rails 3.2.8)
irb(main):001:0> u=User.first
User Load (0.2ms) SELECT "users".* FROM "users" LIMIT 1
=> #<User id: 1, name: "scorpio_et", passwd: "xxx", updated_at: "2013-01-07 12:09:26",expire_time: "2000-01-01 12:09:15">
irb(main):002:0> u.expire_time=Time.now
=> 2013-01-07 20:16:39 +0800
次に、 u.save を実行します。出力から、機能しているようです
irb(main):003:0> u.save
(0.1ms) begin transaction
(0.5ms) UPDATE "users" SET "expire_time" = '2013-01-07 12:16:39.628766', "updated_at" = '2013-01-07 12:16:42.816250' WHERE "users"."id" = 1
(85.9ms) commit transaction
=> true
しかし、データベースからフェッチすると、「expire_time」フィールドは変更されませんでした
irb(main):004:0> User.first
User Load (0.4ms) SELECT "users".* FROM "users" LIMIT 1
=> #<User id: 1, name: "scorpio_et", passwd: "xxx", updated_at: "2013-01-07 12:16:42", expire_time: "2000-01-01 12:16:39">
save!' ,it didn't throw exception,and the output is identical with the
save'を使用すると、他のフィールドを更新できます。これが schema.rb です: ActiveRecord::Schema.define(:version => 20130107073652) do
create_table "users", :force => true do |t|
t.string "name"
t.string "passwd"
t.string "jsoncookie"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.time "expire_time"
end
時間に気付きましたexpire_time' field is
が、それは「datetime」であるべきだと思います
私の移行は: class AddExpireTimeToUsers < ActiveRecord::Migration def change add_column :users, :expire_time, :datatime end end