0
にレール5 attibutesのAPIストアを使用して、私は、ユーザーと呼ばれるモデルを作成した私のアプリ/モデル/ dob_type.rbのget MM/DD/YY形式として、日付とデータベース
class DobType < ActiveRecord::Type::Datetime
def cast(value)
old_format = value.split('/')
new_format = old_format[2] + '-' + old_format[0] + '-' + old_format[1]
super new_format
end
end
以下、cast_type日時を継承していますpostgres.hereにdatetimeカラムにmm/dd/YY文字列を格納したい場合は、以下のコードを参考にしてください。
class User < ApplicationRecord
attribute :dob, DobType.new
end
と私は次のようにユーザーオブジェクトを作成しようとしています:
user = User.create({:name => 'Jr. Adam Joe', :dob => '01/05/2016'})
その私に
uninitialized constant ActiveRecord::Type::Datetime
任意のwayoutを与えますか?前もって感謝します。