我有一个Rails 4应用程序,我正在尝试管理员选择预约时间。
var Matrix = (function () {
function Matrix(element) {
this.ctm = element.getScreenCTM();
this.element = element;
}
Matrix.prototype.apply = function () {
this.element.setAttribute("transform", "matrix(" + this.ctm.a + "," + this.ctm.b + "," + this.ctm.c + "," + this.ctm.d + "," + this.ctm.e + "," + this.ctm.f + ")");
};
Matrix.prototype.flip = function (x, y) {
if (x) {
this.ctm = this.ctm.flipX();
}
if (y) {
this.ctm = this.ctm.flipY();
}
this.apply();
};
Matrix.prototype.rotate = function (a, cx, cy) {
if (a === void 0) { a = 0; }
this.ctm = this.ctm.rotate(a);
if (cx && cy) {
this.ctm = this.ctm.rotateFromVector(cx, cy);
}
this.apply();
};
Matrix.prototype.translate = function (x, y) {
if (x === void 0) { x = 0; }
if (y === void 0) { y = 0; }
this.ctm = this.ctm.translate(x, y);
this.apply();
};
return Matrix;
})();
除了验证日期之外,我的模型对日期没有任何作用。 在我的数据库(Sqlite)中,它将它们存储为时间对象。
我的控制器:
...
<div class="field">
<%= f.label :start_time %><br>
<%= f.datetime_select :start_time %>
</div>
<div class="field">
<%= f.label :end_time %><br>
<%= f.datetime_select :end_time %>
</div>
...
我已将默认时区更改为:
def create
@user = User.find(params[:user_id])
@appointment = @user.appointments.build(appointment_params)
...
end
...
def appointment_params
params.require(:appointment).permit(:start_time, :end_time, :comments)
end
问题
我通过表单创建,然后像这样检查Rails控制台:
config.time_zone = "Pacific Time (US & Canada)"
即使我选择了(默认情况下是2015年),我也会得到这个。为什么Rails会像2000年那样存储年份?
修改 - 迁移
Loading development environment (Rails 4.2.2)
>> appointment = Appointment.all.last
Appointment Load (0.2ms) SELECT "appointments".* FROM "appointments" ORDER BY "appointments"."id" DESC LIMIT 1
=> #<Appointment id: 8, user_id: 1, comments: "", start_time: "2000-01-01 12:50:00", end_time: "2000-01-01 12:50:00">
>> appointment.start_time.year
=> 2000
架构:
class ChangeTimeInAppointments < ActiveRecord::Migration
def change
remove_column :appointments, :time
add_column :appointments, :start_time, :time
add_column :appointments, :end_time, :time
end
end